mugdha r.
2013-Jun-18 18:28 UTC
How to Pass Jquery selected dropdown values and radio button values to controller
Hi, I have an advance search page and its code is as follows - I have written my code like this <div class="container"> <%= form_tag search_index_path, method: :get do %> <%= radio_button_tag ''user_type'', ''customer'' %><p>Customer</p> <%= radio_button_tag ''user_type'', ''supplier'' %><p>Supplier</p> <% end %> <h2>Search Criteria</h2> <div id="dropdown"> <p>State</p> <%= collection_select(:customer, :customer_number, Customer.all, :id, :state) %> <p>City</p> <%= collection_select(:customer, :customer_number, Customer.all, :id, :city) %> <p>Name</p> <%= collection_select(:customer, :customer_number, Customer.all, :id, :name) %> </div> <div id="dropdown1"> <p>State</p> <%= collection_select(:supplier, :supplier_number, Supplier.all, :id, :state) %> <p>City</p> <%= collection_select(:supplier, :supplier_number, Supplier.all, :id, :city) %> <p>Name</p> <%= collection_select(:supplier, :supplier_number, Supplier.all, :id, :name) %> </div> </div> <%= submit_tag "Search", name: nil %> <script> $(document).ready(function() { $("#dropdown").hide(); $("#dropdown1").hide(); $("input[type=''radio''][name=''user_type''][value=''customer'']").click(function(){ $("#dropdown1").hide(); $("#dropdown").show(); $("input[type=''radio''][name=''user_type''][value=''supplier'']").click(function(){ $("#dropdown").hide(); $("#dropdown1").show(); }); }); }); </script> I have two models and controllers for customer and supplier respectively. Now after selecting the values on search page when user click on search how to pass these values to controller so that it will return search results from model. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c44fcfe02abd942232f06e9bc28ae133%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
Rafal Stepien
2013-Jun-19 14:01 UTC
Re: How to Pass Jquery selected dropdown values and radio button values to controller
Hi, Maybe you can check those http://railscasts.com/episodes/88-dynamic-select-menus http://railscasts.com/episodes/111-advanced-search-form Rafal 2013/6/18 mugdha r. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>> Hi, > > I have an advance search page and its code is as follows - > > I have written my code like this > <div class="container"> > <%= form_tag search_index_path, method: :get do %> > <%= radio_button_tag ''user_type'', ''customer'' %><p>Customer</p> > <%= radio_button_tag ''user_type'', ''supplier'' %><p>Supplier</p> > <% end %> > <h2>Search Criteria</h2> > <div id="dropdown"> > <p>State</p> > <%= collection_select(:customer, :customer_number, Customer.all, > :id, :state) %> > <p>City</p> > <%= collection_select(:customer, :customer_number, Customer.all, > :id, :city) %> > <p>Name</p> > <%= collection_select(:customer, :customer_number, Customer.all, > :id, :name) %> > </div> > <div id="dropdown1"> > <p>State</p> > <%= collection_select(:supplier, :supplier_number, Supplier.all, > :id, :state) %> > <p>City</p> > <%= collection_select(:supplier, :supplier_number, Supplier.all, > :id, :city) %> > <p>Name</p> > <%= collection_select(:supplier, :supplier_number, Supplier.all, > :id, :name) %> > </div> > </div> > > <%= submit_tag "Search", name: nil %> > <script> > $(document).ready(function() { > $("#dropdown").hide(); > $("#dropdown1").hide(); > > $("input[type=''radio''][name=''user_type''][value=''customer'']").click(function(){ > $("#dropdown1").hide(); > $("#dropdown").show(); > > $("input[type=''radio''][name=''user_type''][value=''supplier'']").click(function(){ > $("#dropdown").hide(); > $("#dropdown1").show(); > > }); > }); > }); > </script> > > I have two models and controllers for customer and supplier > respectively. Now after selecting the values on search page when user > click on search how to pass these values to controller so that it will > return search results from model. > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/c44fcfe02abd942232f06e9bc28ae133%40ruby-forum.com > . > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAEPaNnsOmPGrx4_uCTV3mUXiWPqhaO8FKwTaRObpT%2B%2BczeM2FA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.