i was wondering if there was any conventional way to find out (via the
partialname_counter, or any other way) which partial is the last in a
set of partials ( render :partial => ‘name’, :collection =>
@somethings’) so that i can display some kind of variable in the last

there’s got to be some neat way to do this?
(like setting :locals => {:abc => @var} if partialname_counter == LAST)


Shai -

Interesting Idea.

If its a display issue then would displaying it after the loop calling
collection of partials be acceptible?


in controller

render :action => ‘list’

in list.rhtml

<%= render :partial => ‘mypartial’, :collection => @mypartials %>
<%= display_cool_stuff_for( @var ) -%>

If its a data issue then I suppose the following might work.

in list.rhtml

<% @mypartials.each_with_index do | part, ii | %>
<% if ii + 1 == @mypartials.size %>
<%= render :partial => ‘mypartial’, :locals=> { :mypartial => part,
:other => @var } %>
<% else %>
<%= render :partial => ‘mypartial’, :locals => { :mypartial => part
} %>
<% end %>
<% end %>


  • trav

Hi travis,

'tis an interesting idea; i was actually visualizing some kind of rails
magic (like partialname_counter.last) to do the above, instead of
defining a each_with_index on an array of partials…
i already got the solution done by passing:

<%= render :partial => ‘object’, :collection => @objects, :locals =>

and then, in the partial itself i put my variable
<% if object == @objects.last %>…@var…<% end %>
which worked fine…i was just hoping to see if there was some kind of
rails method for doing this when calling a collection of partials that
could be inserted in the _partial.rhtml

either way, thanks for the speedy reply,
and regards back 2 u,