Marcos Serpa
2012-Apr-30 15:52 UTC
How to pass the selected value to controller through ''link_to''?
Hello, guys. I''m searching for days, but I''m not finding a way to do this. How can I pass like an argument by ''link_to'' the selected value of a selected_tag? Like this: <%= select_tag ''cities'', options_from_collection_for_select(@cities, ''id'', ''city'') %> <%= link_to "See", deals_path(:id => ??) %> Just to clarify, all the code below is working perfectly. I just don''t know what I put in ''??'' on the ":id => ??" to pass the selected value of the select_tag. To make easy in your minds, remember the Groupon site. The deals page. When you choose a place, then the deals showed to you is only the deals of that place. Exactly what I want... OBS: This is not a form. Just an index page that show a list of things of the database. Got this, guys? Can you help me? Hug! -- 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/-/fECCwFx5SNwJ. 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.
Javier Quarite
2012-Apr-30 20:45 UTC
Re: How to pass the selected value to controller through ''link_to''?
On Mon, Apr 30, 2012 at 10:52 AM, Marcos Serpa <marcosserpa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Hello, guys. > > I''m searching for days, but I''m not finding a way to do this. How can I > pass like an argument by ''link_to'' the selected value of a selected_tag? > Like this: > > <%= select_tag ''cities'', options_from_collection_for_select(@cities, ''id'', > ''city'') %> > > <%= link_to "See", deals_path(:id => ??) %> > > Just to clarify, all the code below is working perfectly. I just don''t > know what I put in ''??'' on the ":id => ??" to pass the selected value of > the select_tag. > > To make easy in your minds, remember the Groupon site. The deals page. > When you choose a place, then the deals showed to you is only the deals of > that place. Exactly what I want... > > OBS: This is not a form. Just an index page that show a list of things of > the database. > > Got this, guys? Can you help me? > > Hug! >I guess that instead of a link_to, should be a form. You should do a form_tag and inside that the selector, so when you click on the "View" button it will make a request of the selected option. Now if you want to do all of that without "refreshing" the browser, you could do an ajax call and you have to add :remote=>true to your form_tag options If you want to add the ID to that link (html) you will have to add some javascript in order to update the link value JavierQ -- 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.
Robert Walker
2012-Apr-30 20:55 UTC
Re: How to pass the selected value to controller through ''link_to''?
Marcos Serpa wrote in post #1058999:> I''m searching for days, but I''m not finding a way to do this. How can I > pass like an argument by ''link_to'' the selected value of a selected_tag? > Like this: > > <%= select_tag ''cities'', options_from_collection_for_select(@cities, > ''id'', > ''city'') %> > > <%= link_to "See", deals_path(:id => ??) %> > > Just to clarify, all the code below is working perfectly. I just don''t > know > what I put in ''??'' on the ":id => ??" to pass the selected value of the > select_tag.Okay, the first thing to realize is that a selection made by the user using a select control does not notify the server of any change. The browser downloads the page. The user makes their selection and "posts" the form back to the server. There is nothing you can do server-side to detect the selection when it actually occurs. You will need to handle this on the client side using JavaScript. There are multiple ways to handle that. I''ll leave that as an exercise for you. If you have any specific questions during the implementation of that then please ask. -- 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.