The rails docs are so horrible on the collection_select method. They need to show a *complete* form, and show two examples: one that calls f.collection_select(), and another that calls collection_select(), and explain the differences. Given this line: f.collection_select :topic, Topic.all, :id, :category What the !@#$!@#$ is :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-/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.
the field name: collection_select(:post, :author_id, Author.all, :id, :name_with_initial, :prompt => true) will generate: <select name="post[author_id]"> <option value="">Please select</option> <option value="1" selected="selected">D. Heinemeier Hansson</option> <option value="2">D. Thomas</option> <option value="3">M. Clark</option> </select> look fella, for docs look at http://apidock.com/rails is awesome and much better see ya and any questions, please just ask :) Em 10/08/2011, às 21:52, 7stud -- escreveu:> The rails docs are so horrible on the collection_select method. They > need to show a *complete* form, and show two examples: one that calls > f.collection_select(), and another that calls collection_select(), and > explain the differences. > > Given this line: > > f.collection_select :topic, Topic.all, :id, :category > > What the !@#$!@#$ is :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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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. >-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Given this line: f.collection_select :topic, Topic.all, :id, :category If I give rails a collection (Topic.all), and the value attribute of the <option> tag (:id), and the display text (:category), why would rails need to know anything else? -- 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.
Leoncio Caminha wrote in post #1016087:> the field name: > collection_select(:post, :author_id, Author.all, :id, > :name_with_initial, :prompt => true) > will generate: > > <select name="post[author_id]"> > <option value="">Please select</option> > <option value="1" selected="selected">D. Heinemeier Hansson</option> > <option value="2">D. Thomas</option> > <option value="3">M. Clark</option> > </select> > >Okay, so it looks like the first two arguments determine the name of the select? But don''t the arguments change if you call: f.collection_select(....) ??? -- 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.
7stud -- wrote in post #1016089:> Leoncio Caminha wrote in post #1016087: >> the field name: >> collection_select(:post, :author_id, Author.all, :id, >> :name_with_initial, :prompt => true) >> will generate: >> >> <select name="post[author_id]"> >> <option value="">Please select</option> >> <option value="1" selected="selected">D. Heinemeier Hansson</option> >> <option value="2">D. Thomas</option> >> <option value="3">M. Clark</option> >> </select> >> >> > > Okay, so it looks like the first two arguments determine the name of the > select?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.> But don''t the arguments change if you call: > > f.collection_select(....) > > > ???-- 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.
Walter Lee Davis
2011-Aug-11 03:01 UTC
Re: Re: f.collection_select: what are the parameters?
On Aug 10, 2011, at 9:53 PM, 7stud -- wrote:> 7stud -- wrote in post #1016089: >> Leoncio Caminha wrote in post #1016087: >>> the field name: >>> collection_select(:post, :author_id, Author.all, :id, >>> :name_with_initial, :prompt => true) >>> will generate: >>> >>> <select name="post[author_id]"> >>> <option value="">Please select</option> >>> <option value="1" selected="selected">D. Heinemeier Hansson</ >>> option> >>> <option value="2">D. Thomas</option> >>> <option value="3">M. Clark</option> >>> </select> >>> >>> >> >> Okay, so it looks like the first two arguments determine the name >> of the >> select? > > 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> ... If you wanted to pick a favorite color from an array, you could do that like this: <%= f.collection_select :favorite_color %W(red green blue), :to_s, :titleize, :prompt => true %> That gives you: <select name="post[favorite_color]" id="post_favorite_color" size="1"> <option value="">Please choose...</option> <option value="red">Red</option> ... In either case, when you create or update a Post, you send the hash params[:post] to its ccontroller, and all the parameters nested inside of that hash are untwisted in there and assigned to the object. It''s really very flexible. Walter> > >> But don''t the arguments change if you call: >> >> f.collection_select(....) >> >> >> ??? > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- 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.
Walter Davis wrote in post #1016097:> On Aug 10, 2011, at 9:53 PM, 7stud -- wrote: >Hi, Thanks for the response.>>>> 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? >Why should I have to assume that? Why can''t the form select with all the users and their ids, and then the action that the form is submitted to sends a birthday email to the selected user? Or is that what form_for(@user) locks me into? -- 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.
Leoncio Caminha
2011-Aug-11 10:28 UTC
Re: Re: f.collection_select: what are the parameters?
dude, its a encapsulete form in html....one specie of object orientation you know? its simple...open your mind its easy any doubts, please, ask :) Enviado via iPad Em 10/08/2011, às 22:53, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> escreveu:> 7stud -- wrote in post #1016089: >> Leoncio Caminha wrote in post #1016087: >>> the field name: >>> collection_select(:post, :author_id, Author.all, :id, >>> :name_with_initial, :prompt => true) >>> will generate: >>> >>> <select name="post[author_id]"> >>> <option value="">Please select</option> >>> <option value="1" selected="selected">D. Heinemeier Hansson</option> >>> <option value="2">D. Thomas</option> >>> <option value="3">M. Clark</option> >>> </select> >>> >>> >> >> Okay, so it looks like the first two arguments determine the name of the >> select? > > 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. > > > >> But don''t the arguments change if you call: >> >> f.collection_select(....) >> >> >> ??? > > -- > 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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Leoncio Caminha wrote in post #1016134:> dude, its a encapsulete form in html....one specie of object orientation > you know? its simple...open your mind its easy >Don''t bother making posts like 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-/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.
On Aug 11, 5:46 am, 7stud -- <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Walter Davis wrote in post #1016097: > > > 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? > > Why should I have to assume that? Why can''t the form select with all > the users and their ids, and then the action that the form is submitted > to sends a birthday email to the selected user? Or is that what > form_for(@user) locks me into? >It''s what''s in the action processing the form data that dictates what the data submitted by the form should look like. form_for(@user) and using example like Walter''s go hand in hand with being able to just do @user.update_attributes(params[:user]) Fred> -- > Posted viahttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 11, 1:52 am, 7stud -- <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> The rails docs are so horrible on the collection_select method. They > need to show a *complete* form, and show two examples: one that calls > f.collection_select(), and another that calls collection_select(), and > explain the differences. >The different between random_helper and f.random_helper is that in the first case, the first argument is used to determine what model object is being edited. In the second case that argument is superfluous since the form builder (f) already has that information.> Given this line: > > f.collection_select :topic, Topic.all, :id, :category > > What the !@#$!@#$ is :topic?the name of the attribute being edited Fred> > -- > Posted viahttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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-/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.
On 11 August 2011 19:02, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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?See the Rails Guide on Associations. Make sure you completely understand what is there, it is vital to understanding Rails. Colin -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2011-Aug-11 22:38 UTC
Re: Re: Re: f.collection_select: what are the parameters?
On Aug 11, 2011, at 2:02 PM, 7stud -- wrote:> I don''t know anything about associations yet. Is topic_id a field in > the Post model when a Post has_one :topic?Yes. Walter -- 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.
Colin Law wrote in post #1016241:> On 11 August 2011 19:02, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>> >>> <%= form_for @post do |f| %> >>> >> >> >> I don''t know anything about associations yet. Is topic_id a field in >> the Post model when a Post has_one :topic? > > See the Rails Guide on Associations. Make sure you completely > understand what is there, it is vital to understanding Rails. >I read it. Not very good. I''ll have to read up on some database theory. Walter Davis wrote in post #1016265:> On Aug 11, 2011, at 2:02 PM, 7stud -- wrote: > >> I don''t know anything about associations yet. Is topic_id a field in >> the Post model when a Post has_one :topic? > > Yes.Thanks. -- 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.
Chris Mear
2011-Aug-12 00:31 UTC
Associations Guide (was Re: Re: Re: Re: f.collection_select: what are the parameters?)
On 12 Aug 2011, at 01:15, 7stud -- wrote:> Colin Law wrote in post #1016241: > >> On 11 August 2011 19:02, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >>> I don''t know anything about associations yet. Is topic_id a field in >>> the Post model when a Post has_one :topic? >> >> See the Rails Guide on Associations. Make sure you completely >> understand what is there, it is vital to understanding Rails. > > I read it. Not very good. I''ll have to read up on some database > theory.It would be useful to know in particular what you found lacking in the Associations Guide, so that we (the community) can improve it. My own first impression of it is that it pretty much assumes the reader is already familiar with foreign keys (fields like ''topic_id''). Is that the same thing you found? Chris -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11 August 2011 23:38, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> > On Aug 11, 2011, at 2:02 PM, 7stud -- wrote: > >> I don''t know anything about associations yet. Is topic_id a field in >> the Post model when a Post has_one :topic? > > Yes.No, Post has a topic_id field if Post belongs_to :topic. If Post has_one topic then Topic belongs_to Post so Topic will have a post_id Colin -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Aug-12 07:19 UTC
Re: Re: Re: Re: f.collection_select: what are the parameters?
On 12 August 2011 01:15, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #1016241: >> On 11 August 2011 19:02, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>>> >>>> <%= form_for @post do |f| %> >>>> >>> >>> >>> I don''t know anything about associations yet. Is topic_id a field in >>> the Post model when a Post has_one :topic? >> >> See the Rails Guide on Associations. Make sure you completely >> understand what is there, it is vital to understanding Rails. >> > > I read it. Not very good. I''ll have to read up on some database > theory.What do you mean "not very good", do you mean your understanding of it is not very good? Colin -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.