SearchRails

A Simple Search Gem For Ruby On Rails

Installation

Add this line to your application's Gemfile:

gem 'search_rails'
gem 'colorize'

And then execute:

$ bundle install

Usage

To install the search functionality not using Devise, type the command:

$ search:install

To install the search functionality using Devise, type the command:

$ search:install:devise

Then follow the steps below.

The syntax for installing the search function is shown in the example below, as if you are installing it for the table 'humans' and the attributes 'name' (string) and 'age' (integer):

$ install humans name:string age:integer

After that run:

$ rake db:migrate

Then insert the following form on whatever page you have set up for the search function:

<%= form_for @search do |f| %>
  <%= f.text_field :search %>
  <%= link_to 'x', clear_search_path(@search) %>
<% end -%>

If you are not using Devise, add the following lines to whatever controller action you want to have the search functionality in.

$LOAD_PATH.unshift(File.dirname('../app/search'))
extend SearchModule
@search = Search.find_by_search_id(1)
if @search.search != nil
  search()
end

If you are using Devise, add the following lines to whatever controller action you want to have the search functionality in.

$LOAD_PATH.unshift(File.dirname('../app/search'))
extend SearchModule
@search = Search.find_by_user_id(current_user.id)
if @search.search != nil
  search()
end

This is still a work in progress, so if there are any issues, please report them on the GitHub page.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/micahnico/search_rails.

License

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