Hai friends, I am really new to ROR I have some radiobuttons...If user select a radiobutton i want to get the id of the selected radio button to be passed as an id to the index page of weather controller on clicking the button "view Details" I don''t know how to pass the id? Can you please help me out. View <% for r in @readings %> <%= radio_button :contact_preference, "value", :tabindex =>r.id %> <%=h r.station.province %> <%end%> <%= button_to "View Details", :controller => "weather", :action => "index" %> Thanks, Veena -- 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.
Why don''t you try googling a little. All you need here inside the loop <% for r in @readings %> is -------------------------- <%= radio_button_tag ''contact_preference_id'', "#{r.id}", false, :class=> "classname_if_any"%> RED is the name of the radio buttons, must be same for all the other radio buttons to facilitate, User must be able to select only one of the radio buttons in the current_readings list. GREEN is the value of the radio button, i.e. the id of the current_reading. It will be different for every radio button. BLUE is whether that radio button should be checked or not. But initially you should keep it false only. When user wish to he might select one of them. GREY is the class variable you want to set to apply some css class to improve the look of the radio button. ......#Rest of the code you already have below And inside the weather_controller in def index action, do something like - if request.post? #That means someone clicked view Details link. And you check the value of params[:contact_preference_id], will give you id of the selected radio button. good luck, Nitin. On Wed, Mar 10, 2010 at 4:06 PM, Veena Jose <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > Hai friends, > > I am really new to ROR > I have some radiobuttons...If user select a radiobutton i want to get > the id of the selected radio button to be passed as an id to the index > page of weather controller on clicking the button "view Details" > I don''t know how to pass the id? Can you please help me out. > > View > > <% for r in @readings %> > <%= radio_button :contact_preference, "value", :tabindex =>r.id %> > <%=h r.station.province %> > <%end%> > <%= button_to "View Details", :controller => "weather", :action => > "index" %> > > Thanks, > Veena > -- > 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<rubyonrails-talk%2Bunsubscribe-/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.
Hai Nitin, Thank you once again...But i am not getting the id of the selected radio button.After selecting and clicking "view details" link,it is again directing to the same page.(readings/index) readings/index.html.erb <% for r in @readings %> <%= radio_button_tag ''contact_preference_id'', "#{r.id}", false %> <%=h r.station.province %> <%end%> <%= link_to "View Details", :controller => "weather", :action => "index" %> Weather Controller def index if request.post? station = Station.find(params[:contact_preference_id]) @readings=CurrentReading.find_all_by_station_id(station) else redirect_to(:controller =>"readings",:action =>"index") end end Thanks, Veena -- 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.
*<%= radio_button_tag ''contact_preference_id'', ''#{r.id}'' %> <%=h r.station.province %> * On Thu, Mar 11, 2010 at 10:31 AM, Veena Jose <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > Hai Nitin, > Thank you once again...But i am not getting the id of the selected > radio button.After selecting and clicking "view details" link,it is > again directing to the same page.(readings/index) > > > readings/index.html.erb > > <% for r in @readings %> > <%= radio_button_tag ''contact_preference_id'', "#{r.id}", false %> > <%=h r.station.province %> > <%end%> > <%= link_to "View Details", :controller => "weather", :action => > "index" %> > > > Weather Controller > def index > if request.post? > station = Station.find(params[:contact_preference_id]) > @readings=CurrentReading.find_all_by_station_id(station) > else > redirect_to(:controller =>"readings",:action =>"index") > end > end > > Thanks, > Veena > -- > 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<rubyonrails-talk%2Bunsubscribe-/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.
Bala wrote:> *<%= radio_button_tag ''contact_preference_id'', ''#{r.id}'' %> <%=h > r.station.province %> > *Still facing same problem.... Thanks, veena -- 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.
Try this... INSIDE VIEW - ----------------------------------------------------------------------------------------------- <% form_tag :controller => "readings", :action =>"index" do %> <% for r in @readings %> <div><%= radio_button_tag ''contact_preference_id'', "#{r.station.id}", false %><%=h r.station.stats %></div> <%end%> <%= submit_tag "View Details" %> <% end %> INSIDE CONTROLLER - ------------------------------------------------------------------------------------------------ @readings = CurrentReadings.find(:all) if request.post? #do something station = Station.find(params[:contact_preference_id]) @readings=CurrentReading.find_all_by_station_id(station) end INSIDE MODEL- ------------------------------------------------------------------------------------------------ def stats "#{self.name}-#{self.unit_id}, #{self.province.nil? ? '''' : self.province+'', ''} #{self.state.titleize}" end good luck (You really need to modify all this according to your requirement. I just took an example case similar to your DATABASE) Nitin. On Thu, Mar 11, 2010 at 11:33 AM, Veena Jose <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Bala wrote: > > *<%= radio_button_tag ''contact_preference_id'', ''#{r.id}'' %> <%=h > > r.station.province %> > > * > > Still facing same problem.... > Thanks, > veena > -- > 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<rubyonrails-talk%2Bunsubscribe-/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.
you have to add the r.id to the link dynamically which can be used by javascript . onclick the radio button you have to add ''? contact_reference_id=checked element id'' On Mar 11, 11:33 am, Nitin Rajora <nitinr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Try this... > INSIDE VIEW - > ----------------------------------------------------------------------------------------------- > <% form_tag :controller => "readings", :action =>"index" do %> > <% for r in @readings %> > <div><%= radio_button_tag ''contact_preference_id'', "#{r.station.id}", > false %><%=h r.station.stats %></div> > <%end%> > <%= submit_tag "View Details" %> > <% end %> > > INSIDE CONTROLLER - > ------------------------------------------------------------------------------------------------ > @readings = CurrentReadings.find(:all) > if request.post? > #do something > station = Station.find(params[:contact_preference_id]) > @readings=CurrentReading.find_all_by_station_id(station) > end > > INSIDE MODEL- > ------------------------------------------------------------------------------------------------ > def stats > "#{self.name}-#{self.unit_id}, #{self.province.nil? ? '''' : > self.province+'', ''} #{self.state.titleize}" > end > > good luck (You really need to modify all this according to your requirement. > I just took an example case similar to your DATABASE) > Nitin. > > On Thu, Mar 11, 2010 at 11:33 AM, Veena Jose <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > Bala wrote: > > > *<%= radio_button_tag ''contact_preference_id'', ''#{r.id}'' %> <%=h > > > r.station.province %> > > > * > > > Still facing same problem.... > > Thanks, > > veena > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you soooooooooo much Nitin <%= submit_tag "View Details" %> This has worked for me. Thanks and Regards, Veena -- 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.