Reputation: 1032
I have a requirement to create a filter in the index page, I do not have much idea on jQuery/AJAX, please help me in creating the code
// index view
- @results.each do |result|
%tr
%td= result.test.name
%td= result.status
Here is my controller
def index
@results = Result.all
end
Upvotes: 2
Views: 1746
Reputation: 169
I think you are searching for "SEARCH USING JQUERY".
There is a good tutorial here
First you must create your controller like this:
def index
@products = Product.search(params[:search]).order(sort_column + " " + sort_direction).paginate(:per_page => 5, :page => params[:page])
end
Then your model:
def self.search(search)
if search
where('name LIKE ?', "%#{search}%")
else
scoped
end
end
Your index view:
<% form_tag products_path, :method => 'get', :id => "products_search" do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<div id="products"><%= render 'products' %></div>
<% end %>
Javascript view:
$("#products").html("<%= escape_javascript(render("products")) %>");
Upvotes: 1