Note that there are some explanatory texts on larger screens.

plurals
  1. POMultilevel block methods in rails
    primarykey
    data
    text
    <p>I am making a view helper to render set of data in a format. I made these classes</p> <pre><code>require 'app/data_list/helper' module App module DataList autoload :Builder, 'app/data_list/builder' @@data_list_tag = :ol @@list_tag = :ul end end ActionView::Base.send :include, App::DataList::Helper </code></pre> <p>helper is </p> <pre><code>module App module DataList module Helper def data_list_for(object, html_options={}, &amp;block) builder = App::DataList::Builder arr_content = [] object.each do |o| arr_content &lt;&lt; capture(builder.new(o, self), &amp;block) end content_tag(:ol, arr_content.join(" ").html_safe, html_options).html_safe end end end end </code></pre> <p>builder is</p> <pre><code>require 'app/data_list/column' module App module DataList class Builder include App::DataList::Column include ActionView::Helpers::TagHelper include ActionView::Helpers::AssetTagHelper attr_reader :object, :template def initialize(object, template) @object, @template = object, template end protected def wrap_list_item(name, value, options, &amp;block) content_tag(:li, value).html_safe end end end end </code></pre> <p>column module is </p> <pre><code>module App module DataList module Column def column(attribute_name, options={}, &amp;block) collection_block, block = block, nil if block_given? puts attribute_name value = if block block elsif @object.respond_to?(:"human_#{attribute_name}") @object.send :"human_#{attribute_name}" else @object.send(attribute_name) end wrap_list_item(attribute_name, value, options, &amp;collection_block) end end end end </code></pre> <p>Now i write code to test it</p> <pre><code> &lt;%= data_list_for @contracts do |l| %&gt; &lt;%= l.column :age %&gt; &lt;%= l.column :contact do |c| %&gt; &lt;%= c.column :phones %&gt; &lt;% end %&gt; &lt;%= l.column :company %&gt; &lt;% end %&gt; </code></pre> <p>Every thing is working fine , <code>age</code> , <code>contact</code> , <code>company</code> is working fine. But <code>phones</code> for the <code>contact</code> is not showing.</p> <p>Does any one have an idea, i know i have missed something in the code. Looking for your help.</p> <p>Updated question with complete source is <a href="https://stackoverflow.com/questions/5562658/multi-level-block-method-is-generating-issue">enter link description here</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload