Karel Vanhoorebeek
2011-Apr-16 16:14 UTC
Generating forms for array & add elements dynamically
Hi, I''ve been struggling with this for quite some time now, but I feel like I''m almost there. What I have is a model "online_score" which has an array of "online_score_url"s. Those urls have 2 attributes: "url" and "description". I have to create a form that enables you to edit the contents of that array with those "online_score_url"s. Editing and removing work. Adding doesn''t. I have the view part working but I have one big problem, being that the dynamically added urls attributes don''t come in the hash for the url attribute of "online_score". I (think I) know why that happens, but not how to fix it. Why it happens has to do with the "for" attribute in the html code. For fields generated in the "new" view that attribute is as follows: ''for="online_score_url_attributes_0_url"'', but when I add it dynamically its like this: ''for="online_score_item_url"''. If you look at the source code below I think its obvious why that happens, but now to fix it... I guess the thing to do is make sure that the "for" attribute gets set correctly? How? Or is there a better way? Code that matters in attachment Thanks, I hope somebody can help me. Attachments: http://www.ruby-forum.com/attachment/6125/code.txt -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.