[ACCEPTED]-Search in Rails-search
Although this is not a direct answer to 10 your question, here are some resources that 9 may help you as you are learning about search 8 and getting it implemented in your Rails 7 app.
Powerful search functionality with the Sunspot gem
List of the most popular search tools for Ruby
---------------UPDATE----------------
Elasticsearch 6 has been growing in popularity due to some 5 modern awesomeness that it has, such as 4 instant indexing. It has a ruby gem named 3 tire. Definitely worth a look.
---------------UPDATE 2 2----------------
Tire has been retired, and 1 has been replaced by Elasticsearch-ruby
For people coming here and looking for a 5 solution in Rails 4, try the following example:
Posts 4 Controller:
class PostsController < ApplicationController
def index
if params[:search]
@posts = Post.search(params[:search]).order("created_at DESC")
else
@posts = Post.all.order('created_at DESC')
end
end
end
Post Model:
def self.search(search)
# Title is for the above case, the OP incorrectly had 'name'
where("title LIKE ?", "%#{search}%")
end
The index.html.erb 3 remains the same apart from the search form:
<%= form_tag(posts_path, :method => "get", id: "search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: "Search Posts" %>
<%= submit_tag "Search" %>
<% end %>
Note 2 that the paths, controllers and columns 1 you are using may be different.
Elasticsearch with gem searchkick
note: searchkick is also 2 contributed by tire) makes you more comfortable 1 to work on.
For more refer:
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.