can :layout option be passed to render a partial for a collection?

15 views
Skip to first unread message

Alexey Muranov

unread,
Jul 20, 2011, 8:18:40 AM7/20/11
to rubyonra...@googlegroups.com
Hello,
i have read somewhere that calling

<%= render :partial => 'my_partial', :collection => my_collection, :as
=> :model, :layout => 'my_layout' %>

used to render output of
<%= render :partial => 'my_partial', :collection => my_collection, :as
=> :model %>
inside a single layout 'my_layout'.

However, it does not seem to work for me now, and this behavior is not
documented in API pages, the suggested way to do is to yield explicitly:

<%= render :layout => 'my_layout' do %>
<%= render :partial => 'my_partial', :collection => my_collection, :as
=> :model %>
<% end %>

Can anybody please explain if i am doing something wrong, or if this
behavior of :layout option is not supported anymore?

Thanks,

Alexey.

--
Posted via http://www.ruby-forum.com/.

Kendall Gifford

unread,
Jul 20, 2011, 8:44:06 PM7/20/11
to rubyonra...@googlegroups.com
This :layout option isn't supported if you're rendering a collection (I just checked the source code in actionpack-3.0.7/lib/action_view/render/partials.rb, specifically the ActionView::Partials::PartialRenderer#render_collection method)

The "Rendering Collections" section of the "Layouts and Rendering in Rails" guide (http://guides.rubyonrails.org/layouts_and_rendering.html#rendering-collections) makes no mention of supporting the :layout option either. It does have support for a :spacer_template option if that helps.

 

Alexey Muranov

unread,
Jul 24, 2011, 4:48:08 PM7/24/11
to rubyonra...@googlegroups.com
Thank you for clarifying this.
Reply all
Reply to author
Forward
0 new messages