In app\views\expenses\new.html.erb, I (mistakenly) replaced the script/generated: <%= f.label :vendor %><br /> <%= f.text_field :vendor %> with: <%= f.label :vendor %><br /> <% @current_vendors = Vendor.find(:all, :order=>"nickname") %> <%= select_tag "list", options_for_select(@current_vendors) %> This (if I haven''t introduced any typos here) works fine, except that the user-selection doesn''t really populate the database''s vendors column in the expense record. How do I repair this situation? I''d like to restore the the original text field and somehow populate it with the user-selected value from the select control. -- 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.
RichardOnRails wrote:> In app\views\expenses\new.html.erb, I (mistakenly) replaced the > script/generated: > <%= f.label :vendor %><br /> > <%= f.text_field :vendor %> > with: > <%= f.label :vendor %><br /> > <% @current_vendors = Vendor.find(:all, :order=>"nickname") %> > <%= select_tag "list", options_for_select(@current_vendors) %> > > This (if I haven''t introduced any typos here) works fine, except that > the user-selection doesn''t really populate the database''s vendors > column in the expense record. > > How do I repair this situation? I''d like to restore the the original > text field and somehow populate it with the user-selected value from > the select control.Hi, try this <%= select_tag "expense_vendor", options_for_select(@current_vendors) %>. -- 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.
hi RichardOnRails Try this <%= select_tag ''expense[vendor]'', options_for_select(@current_vendors) %> cheers, sameera On Apr 11, 7:18 am, RichardOnRails <RichardDummyMailbox58...-FtJgd9dCuO3JTKoYRCtP1UEOCMrvLtNR@public.gmane.org> wrote:> In app\views\expenses\new.html.erb, I (mistakenly) replaced the > script/generated: > <%= f.label :vendor %><br /> > <%= f.text_field :vendor %> > with: > <%= f.label :vendor %><br /> > <% @current_vendors = Vendor.find(:all, :order=>"nickname") %> > <%= select_tag "list", options_for_select(@current_vendors) %> > > This (if I haven''t introduced any typos here) works fine, except that > the user-selection doesn''t really populate the database''s vendors > column in the expense record. > > How do I repair this situation? I''d like to restore the the original > text field and somehow populate it with the user-selected value from > the select control.-- 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.
PRiyanka and sameera: Thank you both very much!!! I''ve been pulling my hair out for about a week with this thing. I didn''t realize that the first argument of the select_tag function apparently identifies the target of the selected item in the format "table_name[column_name]". Now that you''ve given me this solution, I have to try to implement what seems to me to by the more proper architecture for the Expense/ Vendor relationship, namely have the drop-down populate a hidden text field (representing a expense-table column "vendor_id") and have the vendor name displayed in the expense page but be merely non-editable data not stored in the database. Probably a "has" clause would come into play here. I''m going to take a stab at this, run into a blank wall again, and finally post a more thoughtfully worded question. Best wishes, Richard On Apr 12, 2:11 am, Priyanka Pathak <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> RichardOnRails wrote: > > In app\views\expenses\new.html.erb, I (mistakenly) replaced the > > script/generated: > > <%= f.label :vendor %><br /> > > <%= f.text_field :vendor %> > > with: > > <%= f.label :vendor %><br /> > > <% @current_vendors = Vendor.find(:all, :order=>"nickname") %> > > <%= select_tag "list", options_for_select(@current_vendors) %> > > > This (if I haven''t introduced any typos here) works fine, except that > > the user-selection doesn''t really populate the database''s vendors > > column in the expense record. > > > How do I repair this situation? I''d like to restore the the original > > text field and somehow populate it with the user-selected value from > > the select control. > > Hi, > try this <%= select_tag "expense_vendor", > options_for_select(@current_vendors) %>. > -- > 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.
Hey, Priyanka and Sameera, I''ve thought about design I''m aiming for and realized that I can accomplish it in a very straight-forward way. Again, thanks for your great solution to my original problem. Best wishes, Richard On Apr 10, 10:18 pm, RichardOnRails <RichardDummyMailbox58...-FtJgd9dCuO3JTKoYRCtP1UEOCMrvLtNR@public.gmane.org> wrote:> In app\views\expenses\new.html.erb, I (mistakenly) replaced the > script/generated: > <%= f.label :vendor %><br /> > <%= f.text_field :vendor %> > with: > <%= f.label :vendor %><br /> > <% @current_vendors = Vendor.find(:all, :order=>"nickname") %> > <%= select_tag "list", options_for_select(@current_vendors) %> > > This (if I haven''t introduced any typos here) works fine, except that > the user-selection doesn''t really populate the database''s vendors > column in the expense record. > > How do I repair this situation? I''d like to restore the the original > text field and somehow populate it with the user-selected value from > the select control.-- 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 Apr 12, 8:59 pm, RichardOnRails <RichardDummyMailbox58...-FtJgd9dCuO3JTKoYRCtP1UEOCMrvLtNR@public.gmane.org> wrote:> PRiyanka and sameera: Thank you both very much!!! I''ve been pulling > my hair out for about a week with this thing. > > I didn''t realize that the first argument of the select_tag function > apparently identifies the target > of the selected item in the format "table_name[column_name]". >you could have dodged that if you''d gone with f.select :vendor, choices The second parameter to f.select has the same requirements as what you give to options_for_select Fred> > On Apr 12, 2:11 am, Priyanka Pathak <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > > > RichardOnRails wrote: > > > In app\views\expenses\new.html.erb, I (mistakenly) replaced the > > > script/generated: > > > <%= f.label :vendor %><br /> > > > <%= f.text_field :vendor %> > > > with: > > > <%= f.label :vendor %><br /> > > > <% @current_vendors = Vendor.find(:all, :order=>"nickname") %> > > > <%= select_tag "list", options_for_select(@current_vendors) %> > > > > This (if I haven''t introduced any typos here) works fine, except that > > > the user-selection doesn''t really populate the database''s vendors > > > column in the expense record. > > > > How do I repair this situation? I''d like to restore the the original > > > text field and somehow populate it with the user-selected value from > > > the select control. > > > Hi, > > try this <%= select_tag "expense_vendor", > > options_for_select(@current_vendors) %>. > > -- > > 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.
Hi Frederick, Thanks for your additional help with a simpler solution. I tried to replace my select_tag approach with the f.select approach: <%= f.select :vendor, @current_vendors %> <%# = select_tag "expense[vendor]", options_for_select(@current_vendors) %> 1. The f.select :vendor provided the drop-down control, but selecting an item did not populate the vendor text control, as the former solution did, some I''m sure I misunderstand your intent. 2. I haven''t found documentation for the precise thing you recommended, but I''m hopeful I''ll have some luck with http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html and/or http://guides.rubyonrails.org/form_helpers.html when I get time for careful study. Best wishes, Richard On Apr 13, 1:26 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 12, 8:59 pm, RichardOnRails > > <RichardDummyMailbox58...-FtJgd9dCuO3JTKoYRCtP1UEOCMrvLtNR@public.gmane.org> wrote: > > PRiyanka and sameera: Thank you both very much!!! I''ve been pulling > > my hair out for about a week with this thing. > > > I didn''t realize that the first argument of the select_tag function > > apparently identifies the target > > of the selected item in the format "table_name[column_name]". > > you could have dodged that if you''d gone with f.select :vendor, > choices > The second parameter to f.select has the same requirements as what you > give to options_for_select > > Fred > > > > > On Apr 12, 2:11 am, Priyanka Pathak <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > > RichardOnRails wrote: > > > > In app\views\expenses\new.html.erb, I (mistakenly) replaced the > > > > script/generated: > > > > <%= f.label :vendor %><br /> > > > > <%= f.text_field :vendor %> > > > > with: > > > > <%= f.label :vendor %><br /> > > > > <% @current_vendors = Vendor.find(:all, :order=>"nickname") %> > > > > <%= select_tag "list", options_for_select(@current_vendors) %> > > > > > This (if I haven''t introduced any typos here) works fine, except that > > > > the user-selection doesn''t really populate the database''s vendors > > > > column in the expense record. > > > > > How do I repair this situation? I''d like to restore the the original > > > > text field and somehow populate it with the user-selected value from > > > > the select control. > > > > Hi, > > > try this <%= select_tag "expense_vendor", > > > options_for_select(@current_vendors) %>. > > > -- > > > 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 Apr 13, 8:03 pm, RichardOnRails <RichardDummyMailbox58...-FtJgd9dCuO3JTKoYRCtP1UEOCMrvLtNR@public.gmane.org> wrote:> Hi Frederick, > > Thanks for your additional help with a simpler solution. I tried to > replace my select_tag approach with the f.select approach: > > <%= f.select :vendor, @current_vendors %> > <%# = select_tag "expense[vendor]", > options_for_select(@current_vendors) %> > > 1. The f.select :vendor provided the drop-down control, but > selecting an item did not populate the vendor text control, as the > former solution did, some I''m sure I misunderstand your intent.It''s just a drop down box - it''s not going to do anything to any other control on the page - just pointing out that you don''t need to use select_tag when you have a form builder handing around. Fred -- 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.
Hi Fred, I employed your code and it looks/works great. I could swear my old code populated an adjacent text-box, but I must have been hallucinating. Thank for you additional post which jump-started my effort for neater code. Best wishes, Richard On Apr 14, 7:02 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 13, 8:03 pm, RichardOnRails > > <RichardDummyMailbox58...-FtJgd9dCuO3JTKoYRCtP1UEOCMrvLtNR@public.gmane.org> wrote: > > Hi Frederick, > > > Thanks for your additional help with a simpler solution. I tried to > > replace my select_tag approach with the f.select approach: > > > <%= f.select :vendor, @current_vendors %> > > <%# = select_tag "expense[vendor]", > > options_for_select(@current_vendors) %> > > > 1. The f.select :vendor provided the drop-down control, but > > selecting an item did not populate the vendor text control, as the > > former solution did, some I''m sure I misunderstand your intent. > > It''s just a drop down box - it''s not going to do anything to any other > control on the page - just pointing out that you don''t need to use > select_tag when you have a form builder handing around. > > Fred-- 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.