Wednesday, June 19, 2013

Re: [Rails] 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@ruby-forum.com>
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@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
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@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
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.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate