Local variable passing/scope in nested partials?

Ryan Raaum
Thu, 16 Jun 2005 17:50:11 -0000

Hi everyone,

I managed an ugly kludge solution to my problem, but I feel there must
be a more elegant way of doing it ...

I have a list and I render each element in the list by:

...
<%= render_collection_of_partials "list_entry", @cells %>
...

and in my _list_entry.rhtml partial I''m trying to render a nested
partial form and I need to pass the list_entry accessible object on
into that partial ... and because I am using this form partial from
other places, the local variable in that partial needs to be
''cell''
...  The ugly way I am currently getting this to work is by:

...
<% @cell = list_entry %>
<%= start_form_tag :action => ''update'', :id => @cell
%>
     <%= render_partial "form" %>
...

it seems i should be able to do something like

<%= render(:partial => "form", :cell => list_entry) %>

or

<%= render(:partial => "form", :locals => {:cell =>
list_entry}) %>

which both seem more elegant to me, but neither works.

What am I missing here?

Thanks in advance!

Ryan