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@googlegroups.com.
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.

Search Discussions

  • Aleksey V Zapparov at Jun 25, 2012 at 1:09 pm

    On Mon, 25 Jun 2012 05:31:10 -0700 (PDT) Shalini Sah 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@jabber.ru

    *Origin: Happy Hacking!
  • Aash dhariya at Jun 25, 2012 at 1:10 pm
    <%= 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 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@googlegroups.com.
    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.


    --
    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@googlegroups.com.
    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.
  • Shalini Sah at Jun 25, 2012 at 1:24 pm
    Thank you :) I got it :)
    On Mon, Jun 25, 2012 at 6:40 PM, aash dhariya 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 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@googlegroups.com.
    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.


    --
    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@googlegroups.com.
    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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJun 25, '12 at 12:31p
activeJun 25, '12 at 1:24p
posts4
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase