Forum: Ruby on Rails Reuse Partials

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eugene L. (Guest)
on 2006-05-31 01:18
Hi all,

This is my first official post as RoR developer, so here it is.
I've got a partial for a Address (Postcode, Address, City, ...). I want
to use this partial multiple times on the same form? So I want to fill
in multiple addresses and insert them individualy. How do I go about
doing this?

Kind Regards,
Eugene L.
Stephen B. (Guest)
on 2006-05-31 01:33
Hi,

You can pass a collection argument when you call the partial and it will
render for each object:

<%= render :partial => 'address', :collection => @addresses %>

Check out the render :partial section of the API for more info:
http://api.rubyonrails.com/classes/ActionControlle...

Hope that helps,

Steve


Eugene L. wrote:
> Hi all,
>
> This is my first official post as RoR developer, so here it is.
> I've got a partial for a Address (Postcode, Address, City, ...). I want
> to use this partial multiple times on the same form? So I want to fill
> in multiple addresses and insert them individualy. How do I go about
> doing this?
>
> Kind Regards,
> Eugene L.
Eugene L. (Guest)
on 2006-05-31 02:07
Not exactly,

The addresses is all over the form. Doesn't follow on each other. So the
one is a delivery address and the other a billing address?



Stephen B. wrote:
> Hi,
>
> You can pass a collection argument when you call the partial and it will
> render for each object:
>
> <%= render :partial => 'address', :collection => @addresses %>
>
> Check out the render :partial section of the API for more info:
> http://api.rubyonrails.com/classes/ActionControlle...
>
> Hope that helps,
>
> Steve
>
>
> Eugene L. wrote:
>> Hi all,
>>
>> This is my first official post as RoR developer, so here it is.
>> I've got a partial for a Address (Postcode, Address, City, ...). I want
>> to use this partial multiple times on the same form? So I want to fill
>> in multiple addresses and insert them individualy. How do I go about
>> doing this?
>>
>> Kind Regards,
>> Eugene L.
Eugene L. (Guest)
on 2006-05-31 02:49
I think I've  found the problem, I need to give each partial that I
render a new ID, but how do I go about doing that?

Eugene L. wrote:
> Not exactly,
>
> The addresses is all over the form. Doesn't follow on each other. So the
> one is a delivery address and the other a billing address?
>>
>> Eugene L. wrote:
>>> Hi all,
>>>
>>> This is my first official post as RoR developer, so here it is.
>>> I've got a partial for a Address (Postcode, Address, City, ...). I want
>>> to use this partial multiple times on the same form? So I want to fill
>>> in multiple addresses and insert them individualy. How do I go about
>>> doing this?
>>>
>>> Kind Regards,
>>> Eugene L.
Ben and Kaz A. (Guest)
on 2006-05-31 02:54
(Received via mailing list)
On 5/31/06, Eugene L. <removed_email_address@domain.invalid> wrote:
> Not exactly,
>
> The addresses is all over the form. Doesn't follow on each other. So the
> one is a delivery address and the other a billing address?
>

Look at the :locals parameter in the API docs that Steve pointed you to.

cheers,
Ben
Howard J. (Guest)
on 2007-03-06 22:10
Eugene L. wrote:
> I think I've  found the problem, I need to give each partial that I
> render a new ID, but how do I go about doing that?
>
>> Not exactly,
>>
>> The addresses is all over the form. Doesn't follow on each other. So the
>> one is a delivery address and the other a billing address?
>>>
>>>> Hi all,
>>>>
>>>> This is my first official post as RoR developer, so here it is.
>>>> I've got a partial for a Address (Postcode, Address, City, ...). I want
>>>> to use this partial multiple times on the same form? So I want to fill
>>>> in multiple addresses and insert them individualy. How do I go about
>>>> doing this?

Did you ever get a satisfactory solution to this? I have a similar
problem;
I'd like to reuse a small snippet of HTML several times in a page, with
the
div contents (within the snippet) being arbitrarily large and/or
complex.
As a total beginner, I would have hoped that I could call render
:partial
multiple times, and let it "call back" to let its caller render the
div contents. But I have no idea how to do that.
This topic is locked and can not be replied to.