Reuse Partials


#1

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.


#2

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/ActionController/Base.html#M000206

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.


#3

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.


#4

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


#5

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/ActionController/Base.html#M000206

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.


#6

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.