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 Louw -- Posted via http://www.ruby-forum.com/.
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 Louw 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 Louw-- Posted via http://www.ruby-forum.com/.
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 Bartholomew 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 Louw 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 Louw-- Posted via http://www.ruby-forum.com/.
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 Louw 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 Louw 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 Louw-- Posted via http://www.ruby-forum.com/.
On 5/31/06, Eugene Louw <eugene.louw@gmail.com> 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
> From: Eugene Louw <eugene.louw@gmail.com> > Subject: [Rails] Re: Reuse Partials > 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?Simply create a variable in the main page and that will be available inside the partial. So <% while @counter <@count_to_be_displayed%> <%= render: partial => "partial" <% @counter += 1%> <%end%> In the partial you can access the @counter variable and use that. Hope this is what you were looking for, if not repost with more details and I should be able to help. Just finished some interesting work on partials in my project and so the concepts are very fresh in my mind right now. Bharat
Eugene Louw 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---