[Rails] Partials inside partials

Eric Anderson eric at afaik.us
Mon Jan 3 20:14:48 GMT 2005


Assume we have a ActionView template called foo.rhtml which looks like this:

<%=render_collection_of_partials 'bar', @recs%>

Then we have a file called _bar.rhtml which contains the following:

<%=render_collection_of_partials 'baz', @more_recs%>

@recs and @more_recs are arrays that are defined by the controller. So
now we have a file called _baz.rhtml which need to do something like:

<%=bar.foo(baz)%>

So what we end up with is each object in @recs has the method "foo"
called on it for each object in @more_recs. So basically I am having a
partial include another partial and the final partial will use variables
passed in from the parent partial. Is there anyway to do this or does
Rails only support a single level of partials? I have verified that the
second level of partials is executed but the "bar" variable does not
appear to be in the scope of that second level.

Eric

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
Url : http://one.textdrive.com/pipermail/rails/attachments/20050103/984b77cf/signature.bin


More information about the Rails mailing list