DynamicSearch provides support for multi term searches to your rails models.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
lib
spec
.gitignore
.rspec
Gemfile
Gemfile.lock
MIT-LICENSE
README.md
Rakefile
dynamic_search.gemspec

README.md

DynamicSearch

DynamicSearch provides support for multi term searches to your rails models. At the moment, I would recommend using at least rails 4.2 or higher for security reasons.

Installation

Add this line to your application's Gemfile:

gem 'dynamic_search'

And then execute:

bundle

Or install it yourself as:

gem install dynamic_search

Usage

  1. Include the module to any model you want DynamicSearch functionality.
include DynamicSearch
  1. To use the search you can create a search box form in your view.
<%= form_for :model_name, method: 'get' do |f| %>  
  <%= f.text_field :search, placeholder: "search" %>  
<% end %>  

Then in your controller, you can call the search method on your model. You could also specify the columns you want to search on. If you don't specify columns, DynamicSearch will check against all of the columns on your model except foreign keys, id, and timestamps.

columns_array = ["first_name", "last_name", "username", "email"] 
@results = Model.search(params[:search], columns_array) 

From there I normally would paginate the results with Kaminari or WillPaginate.

Optional Customize the search method in your model to specify how your search should work all the time for that model, instead of just one view like above. In this case, you're telling the search method which columns you want included in your search every time for this model.

def search(search)  
  super(search, ["first_name", "last_name", "username", "email"])  
end  

Contributing

If you find a bug, submit an issue or pull request if you've fixed it. Feel free to reach out on twitter: @jeremydwayne

License

The gem is available as open source under the terms of the MIT License.