Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Commit

Permalink
Install and configure scoped_search.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS committed Aug 2, 2014
1 parent e5d1137 commit 932d0f2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Expand Up @@ -16,6 +16,7 @@ gem 'coffee-rails', '~> 4.0.0'

# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-ui-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
Expand Down Expand Up @@ -44,3 +45,6 @@ gem "codeclimate-test-reporter", group: :test, require: nil

# authentication, require rails 4.1 compatible version
gem 'sorcery', '>= 0.8.6'

# search syntax and autocompletion for search boxes
gem "scoped_search"
6 changes: 6 additions & 0 deletions Gemfile.lock
Expand Up @@ -52,6 +52,8 @@ GEM
jquery-rails (3.1.1)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.0)
railties (>= 3.2.16)
json (1.8.1)
jwt (1.0.0)
mail (2.5.4)
Expand Down Expand Up @@ -97,6 +99,8 @@ GEM
sass (~> 3.2.0)
sprockets (~> 2.8, <= 2.11.0)
sprockets-rails (~> 2.0)
scoped_search (2.7.1)
activerecord (>= 2.1.0)
sdoc (0.4.0)
json (~> 1.8)
rdoc (~> 4.0, < 5.0)
Expand Down Expand Up @@ -142,9 +146,11 @@ DEPENDENCIES
coffee-rails (~> 4.0.0)
jbuilder (~> 2.0)
jquery-rails
jquery-ui-rails
rails (= 4.1.4)
rake
sass-rails (~> 4.0.3)
scoped_search
sdoc (~> 0.4.0)
sorcery (>= 0.8.6)
spring
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Expand Up @@ -12,5 +12,6 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require turbolinks
//= require_tree .
14 changes: 13 additions & 1 deletion app/controllers/people_controller.rb
@@ -1,6 +1,18 @@
class PeopleController < ApplicationController
def index
@people = Person.all
@people = Person.search_for(params[:search], :order => params[:order])
rescue => e
flash[:error] = e.to_s
@people = Person.search_for ''
end

def auto_complete_search
begin
@items = Person.complete_for(params[:search])
rescue ScopedSearch::QueryNotSupported => e
@items = [{:error =>e.to_s}]
end
render :json => @items
end

def new
Expand Down
2 changes: 2 additions & 0 deletions app/models/person.rb
Expand Up @@ -8,6 +8,8 @@ class Person < ActiveRecord::Base
validates_presence_of :email
validates_uniqueness_of :email

scoped_search :on => [ :first_name, :last_name ]

def full_name
[ first_name, middle_name, last_name ].compact.join(' ')
end
Expand Down
7 changes: 7 additions & 0 deletions app/views/people/index.html.erb
@@ -1,5 +1,12 @@
<h1>People</h1>

<div id="people_search">
<%= form_tag people_path, :method => :get do %>
<%= auto_complete_field_tag_jquery(:search, params[:search], {:placeholder => "Type Space For Search Options"}) %>
<button id='submit_search' style="font-size: 12px;">Search</button>
<% end -%>
</div>

<ul>
<% @people.each do |person| %>
<li><%= link_to person.full_name, person %> | <%= link_to "Edit", edit_person_path(person) %> | <%= link_to "Destroy", person, method: :delete %></li>
Expand Down
5 changes: 4 additions & 1 deletion config/routes.rb
Expand Up @@ -21,8 +21,11 @@
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products

resources :people
resources :people do
get :auto_complete_search, :on => :collection
end
get "/people/search/:name", :to => "people#search_by_name"

resources :projects
resources :sessions

Expand Down

0 comments on commit 932d0f2

Please sign in to comment.