Out of curiosity, why is it that the following doesn't work in a view:
<%= @items.each { |@item| render :partial => 'itemrow' } %>
of course it's easily achieved like this:
<% for @item in @items %>
<%= render :partial => 'itemrow' %>
<% end %>
Is it just not possible to use blocks in a view?
}
} Out of curiosity, why is it that the following doesn't work in a view:
}
} <%= @items.each { |@item| render :partial => 'itemrow' } %>
}
} of course it's easily achieved like this:
}
} <% for @item in @items %>
} <%= render :partial => 'itemrow' %>
} <% end %>
}
} Is it just not possible to use blocks in a view?
You would need to use inject rather than each because render :partial
returns the rendered HTML as a string and you are returning @items from
each. That aside, though, the right way to render a partial on a collection
is:
<%= render :partial => 'itemrow', :collection => @items %>
Rails does the loop for you.
--Greg