Skip to content

gaoguoxin/demo_app_for_rails_simple_search

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a rails application. Its purpose is to demo the simplicity and power of gem rails-simple-search.

You can download it and run "bundle; rake db:migrate; rails s" immediately. It's tested under Ruby 1.9.3-p194 and Rails 3.2.6.

In thie demo, I tried to search for a user by part of her name, her post titles, her comments, her address, her city, her state and so on.

The following is the code related to the search:

1. In file "Gemfile"

  ...
  gem 'rails-simple-search', "~> 0.9.3"
  ...

2. In file "app/model"Search"

  class Search < RailsSimpleSearch::Base
  end

3. In file "config/route.rb"
  ...
  match '/users/index', :controller => 'users', :action => "index"
  ...

3. In file "app/controllers/users_controllers"

  ...
  @search = Search.new(:user, params[:search], :per_page => 2)
  @search.order = 'last_name'
  @users = @search.run
  ...
 
4. In file "app/views/users/index.html.erb"
  ...
  <%= form_for @search, :url => "/users/index" do |f| %>
    <%= f.label "First Name" %>
    <%= f.text_field 'first_name' %>
    <br/>
    <%= f.label "Last Name" %>
    <%= f.text_field 'last_name' %>
    <br/>
    <%= f.label "Address1" %>
    <%= f.text_field 'address.address1' %>
    <br/>
    <%= f.label "City" %>
    <%= f.text_field 'address.city' %>
    <br/>
    <%= f.label "Post title" %>
    <%= f.text_field 'posts.title' %>
    <br/>
    <%= f.label "Post body" %>
    <%= f.text_field 'posts.body' %>
    <br/>
    <%= f.label "Comment" %>
    <%= f.text_field 'comments.body' %>
    <br/>
    <%= f.submit "search" %>
  <% end %>
  ...


For more info about rails-simple-search, please see "https://github.com/yzhanginwa/rails-simple-search".

About

Rails 3 application to demo how to use the rails_simple_search

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published