# Reuse Partials

**URL:** <https://www.ruby-forum.com/t/reuse-partials/95388>\
**Category:** Rails\
**Created:** [May 30, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/reuse-partials/95388 "2006-05-30T23:18:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aibean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@aibean](https://www.ruby-forum.com/u/aibean)\
**Post date:** [May 30, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/reuse-partials/95388/1 "2006-05-30T23:18:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aibean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@aibean](https://www.ruby-forum.com/u/aibean)\
**Post date:** [May 30, 2006, 11:33pm UTC](https://www.ruby-forum.com/t/reuse-partials/95388/2 "2006-05-30T23:33:13Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![aibean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@aibean](https://www.ruby-forum.com/u/aibean)\
**Post date:** [May 31, 2006, 12:49am UTC](https://www.ruby-forum.com/t/reuse-partials/95388/3 "2006-05-31T00:49:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aibean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@aibean](https://www.ruby-forum.com/u/aibean)\
**Post date:** [May 31, 2006, 12:54am UTC](https://www.ruby-forum.com/t/reuse-partials/95388/4 "2006-05-31T00:54:19Z")

</div>

On 5/31/06, Eugene L. [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![aibean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@aibean](https://www.ruby-forum.com/u/aibean)\
**Post date:** [May 31, 2006, 12:07am UTC](https://www.ruby-forum.com/t/reuse-partials/95388/5 "2006-05-31T00:07:08Z")

</div>

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:  
> [Peak Obsession](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.

---

<div class="post-metadata">

**Author:** ![aibean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@aibean](https://www.ruby-forum.com/u/aibean)\
**Post date:** [March 6, 2007, 9:10pm UTC](https://www.ruby-forum.com/t/reuse-partials/95388/6 "2007-03-06T21:10:14Z")

</div>

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.
