Hi, I generated through scaffolding products with name and price. In the products/new''s partial _form.html.erb i made a slight change. Instead of having the user to enter the product. I provide a drop down menu replacing : <%=f.text_field :name %> with <%= select_tag(:name, options_for_select([''Peas'',''Butter'',''Garlic''])) %> But when I click on submit the name attribute is nil instead of taking the tag I selected. Please tell me where am I going wrong. Thanks & Regards. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Yg92uN5u7OIJ. 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 Mon, 25 Jun 2012 05:31:10 -0700 (PDT) Shalini Sah <shalinisah6692-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I generated through scaffolding products with name and price. In the > products/new''s partial _form.html.erb i made a slight change. Instead > of having the user to enter the product. I provide a drop down menu > replacing : > > <%=f.text_field :name %> > > with > > <%= select_tag(:name, options_for_select([''Peas'',''Butter'',''Garlic''])) > %> > > But when I click on submit the name attribute is nil instead of > taking the tag I selected. > > Please tell me where am I going wrong.First of all, options_for_select should be: options_for_select([[''Peas'',1],[''Butter'',2],[''Garlic'',3]]) In this case it will give you 1 for Peas, 2 for Butter, etc. In your case you can use it as: options_for_select([''Peas'',''Butter'',''Garlic''].map{ |v| [v,v] }) And after all, I guess you better use `select` helper on a form builder in your case: <%= f.select(:name, options_for_select(...)) %> -- Sincerely yours, Aleksey V. Zapparov A.K.A. ixti FSF Member #7118 Mobile Phone: +34 677 990 688 Homepage: http://www.ixti.net JID: zapparov-962d5TIgE1qHXe+LvDLADg@public.gmane.org *Origin: Happy Hacking!
<%= f.text_field :name%> sets the params array as: params[:product][:name] (provided you have written <%= form_for :product, ... %>) while <%= select_tag(:name, options_for_select([''Peas'',''Butter'',''Garlic''])) %> sets the params array as: params[:name] after submit. Probably, you are accessing the wrong array index. On Mon, Jun 25, 2012 at 6:01 PM, Shalini Sah <shalinisah6692-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Hi, > > I generated through scaffolding products with name and price. In the > products/new''s partial _form.html.erb i made a slight change. Instead of > having the user to enter the product. I provide a drop down menu replacing : > > <%=f.text_field :name %> > > with > > <%= select_tag(:name, options_for_select([''Peas'',''Butter'',''Garlic''])) %> > > But when I click on submit the name attribute is nil instead of taking the > tag I selected. > > Please tell me where am I going wrong. > > Thanks & Regards. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/Yg92uN5u7OIJ. > 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. >-- Thanks, Aash -- 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.
Thank you :) I got it :) On Mon, Jun 25, 2012 at 6:40 PM, aash dhariya <aash.discover-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> <%= f.text_field :name%> sets the params array as: > params[:product][:name] (provided you have written <%= form_for :product, > ... %>) > while <%= select_tag(:name, > options_for_select([''Peas'',''Butter'',''Garlic''])) %> sets the params array as: > params[:name] after submit. > > Probably, you are accessing the wrong array index. > > > On Mon, Jun 25, 2012 at 6:01 PM, Shalini Sah <shalinisah6692-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > >> Hi, >> >> I generated through scaffolding products with name and price. In the >> products/new''s partial _form.html.erb i made a slight change. Instead of >> having the user to enter the product. I provide a drop down menu replacing : >> >> <%=f.text_field :name %> >> >> with >> >> <%= select_tag(:name, options_for_select([''Peas'',''Butter'',''Garlic''])) %> >> >> But when I click on submit the name attribute is nil instead of taking >> the tag I selected. >> >> Please tell me where am I going wrong. >> >> Thanks & Regards. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/Yg92uN5u7OIJ. >> 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. >> > > > > -- > Thanks, > Aash > > -- > 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. >-- 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.