# View
<% form_for @search do |f| %>
<%= f.text_field :keyword %>
<%= f.submit 'Search' %>
<% end %>
# Controller
# Using Seachlogic with Will Paginate
class EnrollmentsController < ApplicationController
def index
@search = Enrollment.search(params[:search])
@enrollments, @enrollments_count = @search.paginate(:include => [{:addresses => :address_type}, :course, :gender], :page => params[:page], :per_page => 20), @search.count
end
end
# Model
# params[:search][:keyword] will trigger keyword namedscope
class Enrollment < ActiveRecord::Base
named_scope :keyword, lambda {|keyword|
{ :conditions => [
"first_name like :word or last_name like :word or nric like :word or date_of_birth like :word or mentor like :word or school_approval_status like :word or student_confirmation_status like :word or genders.name like :word or addresses.handphone like :word or courses.name like :word",
{:word => "%#{keyword}%"}
],
:include => [:addresses, :gender, :course]
}
}
end
Tuesday, August 4, 2009
Implementing "google search" like search field using Searchlogic
I just wanna a single search field like how it is in google.com. This search field should then search through all the desired columns and return records with matches.
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2009
(143)
-
▼
August
(20)
- Open previously closed tabs in Firefox
- Using Mutt to manage your Gmail
- Create & serve a Sinatra app on your iPhone
- Search and Replace in VIM
- Breaking Cucumber feature tests into separate smal...
- Calendar Date Select gem for Rails
- Reload current file in VIM
- Bluetooth tethering your iPhone to Ubuntu (works o...
- Common regular expresssions
- Cucumber > 0.3.7 freezes hash table and changes lo...
- Tech user groups, websites, events and calendars i...
- Shortcut key maps for Vim in normal mode
- Smarter visual highlight in VIM
- Implementing "google search" like search field usi...
- Avoid multi-level associations using named scope
- Table sort with Searchlogic
- Usefulness of named scope in remote console
- Using Searchlogic and Will Paginate
- Check size of folders in terminal
- Toggling between gnome terminal tabs
-
▼
August
(20)
No comments:
Post a Comment