Does anyone know any good "recipe" to have repeatable form elements in Ruby on Rails sites? As an example, let''s say I want users to be able to add as many addresses as possible. An address object consists of two address lines, a city id, and a country id. They can click "Add Another Address" and more address inputs are created on the fly. http://www.quirksmode.org/dom/domform.html - imagine this as an example 1. How do you set the names of the form elements in rails so that they are processed easily? Can you even do this with helpers, or would the necessary elements need to be written and parsed manually? ex. address[:city][], address[:state][] 2. Is there an easy way to keep track of addresses on the page once they are added, assuming they can be updated in text fields? For example, after someone adds an address, and reloads the page, can you say: address[1][:city], or some other name and then have Rails parse this correctly as an object in the params? This would need to also be differentiated from the naming convention in #1, to differentiate existing address objects from new ones. Anyone have any ideas or articles that deal with this issue, or hints on how to make this easier? Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I think this episode might help you... http://railscasts.com/episodes/75 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
See those same Railscasts to which shenry cited David Schwartz for one way to do multiple object creation on a single form: http://railscasts.com/episodes/73 http://railscasts.com/episodes/74 http://railscasts.com/episodes/75 -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of John Sent: Tuesday, June 24, 2008 4:56 PM To: Ruby on Rails: Talk Subject: [Rails] Repeatable Form Elements Does anyone know any good "recipe" to have repeatable form elements in Ruby on Rails sites? As an example, let''s say I want users to be able to add as many addresses as possible. An address object consists of two address lines, a city id, and a country id. They can click "Add Another Address" and more address inputs are created on the fly. http://www.quirksmode.org/dom/domform.html - imagine this as an example 1. How do you set the names of the form elements in rails so that they are processed easily? Can you even do this with helpers, or would the necessary elements need to be written and parsed manually? ex. address[:city][], address[:state][] 2. Is there an easy way to keep track of addresses on the page once they are added, assuming they can be updated in text fields? For example, after someone adds an address, and reloads the page, can you say: address[1][:city], or some other name and then have Rails parse this correctly as an object in the params? This would need to also be differentiated from the naming convention in #1, to differentiate existing address objects from new ones. Anyone have any ideas or articles that deal with this issue, or hints on how to make this easier? Thanks. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---