Hi to everybody! I have a view with a radio-button: I need to pass 2 parameters ("opt.id" and "opt.option") to the relative action; as for the following code I ''ve used, I find in params[:option_id] only the id of the selected option... How can I do to pass also "opt.option"? <% for opt in @options %> <p> <%= label_tag(:answer, opt.option) %> <%= radio_button_tag(:option_id, opt.id, false) %> </p> <% end %> Thank''s to all those who can help me!!! -- 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 Sun, Aug 21, 2011 at 10:00 AM, mr ma <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have a view with a radio-button: I need to pass 2 parameters > ("opt.id" and "opt.option") to the relative action; > as for the following code I ''ve used, I find in params[:option_id] > only the id of the selected option... > How can I do to pass also "opt.option"? > > <% for opt in @options %> > <p> > <%= label_tag(:answer, opt.option) %> > <%= radio_button_tag(:option_id, opt.id, false) %> > </p> > <% end %>If you''re generating these options, shouldn''t you know what option goes with an id? :-) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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.
mr ma wrote in post #1017729:> Hi to everybody! > > I have a view with a radio-button: I need to pass 2 parameters > ("opt.id" and "opt.option") to the relative action; > as for the following code I ''ve used, I find in params[:option_id] > only the id of the selected option... > How can I do to pass also "opt.option"? > > <% for opt in @options %> >Ruby programmers don''t use for-in loops. for-in calls each(), so ruby programmers just call each() directly: <% @options.each do |opt| %> <% end %>> > <p> > <%= label_tag(:answer, opt.option) %> > <%= radio_button_tag(:option_id, opt.id, false) %> > </p> > <% end %> > > Thank''s to all those who can help me!!!You could always do this: <% val = "#{opt_id}-xYz-#{opt.option}" %> <%= radio_button_tag(:option_id, val, false) %> Then in your action: radio_button_results = params[:option_id].split(''-xYz-") -- 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.
mr ma wrote in post #1017729:> Hi to everybody! > > I have a view with a radio-button: I need to pass 2 parameters > ("opt.id" and "opt.option") to the relative action; > as for the following code I ''ve used, I find in params[:option_id] > only the id of the selected option... > How can I do to pass also "opt.option"? > > <% for opt in @options %> > <p> > <%= label_tag(:answer, opt.option) %> > <%= radio_button_tag(:option_id, opt.id, false) %> >..and shouldn''t that label tag be something like this: <%= label_tag("option_id_{#opt.id}", opt.option) %> In other words, according to the rails guide here: http://guides.rubyonrails.org/form_helpers.html ...the id of the radio button becomes the name and value you specify for the radio_button_tag joined together. -- 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.
THANK YOU VERY VERY MUCH!!! ;-) Marco -- 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.