Walter Davis wrote in post #1016097: > On Aug 10, 2011, at 9:53 PM, 7stud -- wrote: > >>>> option> >> And even that isn't entirely correct. Apparently, the name of the >> select has to be of the form: >> >> an_existing_model[:an_existing_field_name_in_that_model] >> >> which doesn't make any sense to me. >> > > I'm not sure why that is -- you're inside of a form builder, building > a form for an object that you plan to modify when you submit that > form, right? What you're describing here is precisely how Rails builds > forms, and what it expects to receive when you send your controller > the params hash. > > Now let's say you want to add a select field to your Post to choose a > Topic. Post has_one :topic. > > <%= form_for @post do |f| %> > > <%= f.collection_select :topic_id, Topic.all, :id, :name, :prompt => > true %> > > That gives you: > > <select name="post[topic_id]" id="post_topic_id" size="1"> > <option value="">Please choose...</option> > <option value="42">Life, the Universe, and Everything</option> > ... >
I don't know anything about associations yet. Is topic_id a field in the Post model when a Post has_one :topic? . . . . . . . -- 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@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.