-
Notifications
You must be signed in to change notification settings - Fork 0
Alternative for searchlogic
License
m4risU/search_alternative
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
SearchAlternative ================= This plugin has been created since searchlogic did not appeared on time when rails 3 appeared in beta. It is supposed to help with table sorting and simple search filters. Example ======= Controller: def index options = {} options[:page] = params[:page] options[:per_page] = 10 @search = User.search(params) @users = @search.paginate(options) end View: Simple searching form, that will use table column <%= form_tag users_path, :method => :get do %> <%= search_tag 'username' %> <%= search_tag 'email' %> <%= submit_tag 'Search' %> <% end %> Some additional filtering outside of form. <%= filter 'fancy_scope', :as => 'Show only those with fancy feature' %> This helper will produce link that will attach some search parametres. It will call on your model scope named filter_by_fancy_scope class User scope :filter_by_fancy_scope, { where("fancy") } end You can pass additional parameter in :filter_params. <%= filter 'fancy_scope', :as => 'Show only those with fancy feature', :filter_params => 34 %> <%= filter 'fancy_scope', :as => 'Show only those with fancy feature', :filter_params => 'fancy_argument' %> <%= filter 'fancy_scope', :as => 'Show only those with fancy feature', :filter_params => [15,67,89] %> You will need of course named scope that will know what to do with this param. As example: class User scope :filter_by_fancy_feature, lambda {|param| where("fancy = ?",param) } end Ordering search_alternative supports ordering with following approach: <%= order @search, :by => 'username', :as => I18n.t('activerecord.attributes.user.username') %> Copyright (c) 2010 [Mariusz Wyrozębski], released under the MIT license
About
Alternative for searchlogic
Resources
License
Stars
Watchers
Forks
Packages 0
No packages published