how do i populate data on table using dropdown in Rails 4.1 -


i have following dropdown:

<%= select_tag 'category', options_from_collection_for_select(@categories, "id", "name"), prompt: "select category"%>

i new in rails.i want show data on table when click on category dropdown.is there way in ruby code.

make following changes in view:

<%= form_tag search_path, :method => 'get' %>   <%= select_tag 'category', options_from_collection_for_select(@categories, "id", "name"), prompt: "select category"%> <%= submit_tag "search", :name => nil %>  <table>   <% @object_for_table.each |object| %>     ----your table data here---   <% end %> </table> 

changes action responsible above view:

def search   @object_for_table = params[:category].blank? ? model.all : model.where(category_id: params[:category]) end 

finally make changes in js submit form on category selection.

$(document).ready(function() {    $("select#category").change(function(){     $(this).closest("form").submit();   });  }); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -