I have a model ''assignment'' that has_many of the model ''answer''. What would be the best way to have a form to save an ''assignment'' and some of its ''answers'' all on the same form? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Brandon wrote:> I have a model ''assignment'' that has_many of the model ''answer''. What > would be the best way to have a form to save an ''assignment'' and some > of its ''answers'' all on the same form?given both models have three attributes, title, content & brief; i believe would this work (untested code) text_field ''assignment'', ''title'' text_field ''assignment'', ''content'' text_field ''assignment'', ''brief'' text_field ''assignment'', ''answer[title]'' text_field ''assignment'', ''answer[content]'' text_field ''assignment'', ''answer[brief]'' -- 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 -~----------~----~----~----~------~----~------~--~---
On Aug 6, 2:37 am, Shai Rosenfeld <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> given both models have three attributes, title, content & brief; > i believe would this work (untested code) > > text_field ''assignment'', ''title'' > text_field ''assignment'', ''content'' > text_field ''assignment'', ''brief'' > text_field ''assignment'', ''answer[title]'' > text_field ''assignment'', ''answer[content]'' > text_field ''assignment'', ''answer[brief]''Hmm... that didn''t work. Also, I need to have more than 1 answer on the form. Maybe something like text fields with id="assignment[answer][1][content]"? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Aug-07 01:13 UTC
Re: What would be the best way to...
Hi -- On Mon, 6 Aug 2007, Brandon wrote:> > > > On Aug 6, 2:37 am, Shai Rosenfeld <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> given both models have three attributes, title, content & brief; >> i believe would this work (untested code) >> >> text_field ''assignment'', ''title'' >> text_field ''assignment'', ''content'' >> text_field ''assignment'', ''brief'' >> text_field ''assignment'', ''answer[title]'' >> text_field ''assignment'', ''answer[content]'' >> text_field ''assignment'', ''answer[brief]'' > > Hmm... that didn''t work. Also, I need to have more than 1 answer on > the form. Maybe something like text fields with > id="assignment[answer][1][content]"?You can give an arbitrary index to text fields, like this: <% @assignment.answers.each_with_index do |answer,i| %> <%= text_field "answer", "title", :index => i %> ... <% end %> You''ll then get params[:answer], which will be a hash with keys corresponding to the indices. Maybe that, or something based on it, would give you what you need. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.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 -~----------~----~----~----~------~----~------~--~---