Every repository with this icon (
Every repository with this icon (
tree 9cee040bc8a1464305475731a3126a31c1aa17bc
parent 48b4e7669b325412fa2ae09f15604dc17d1627f8 parent 0dda70e7a9221057ce60b6c6799c2c0966c6c283
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Mon Nov 03 11:51:24 -0800 2008 | |
| |
README.rdoc | Sat Nov 08 14:43:12 -0800 2008 | |
| |
Rakefile | Tue Oct 07 13:56:45 -0700 2008 | |
| |
TODO | Wed Mar 04 08:44:30 -0800 2009 | |
| |
init.rb | Wed Nov 05 09:43:58 -0800 2008 | |
| |
install.rb | Tue Oct 07 13:56:45 -0700 2008 | |
| |
lib/ | Tue Nov 18 23:14:47 -0800 2008 | |
| |
tasks/ | Tue Oct 07 13:56:45 -0700 2008 | |
| |
test/ | Sun Nov 16 07:43:13 -0800 2008 | |
| |
uninstall.rb | Tue Oct 07 13:56:45 -0700 2008 |
SimplySearchable
SimplySearchable is a search plugin created by Rida Al Barazi - rida.me to be used in SpinBits’s Skeleton App.
The main goal of SimplySearchable is to make it easy to do queries on your model by auto-magically creating some named_scope methods for common conditions, it adds a method to the model named "list" that will find and filter records smartly.
Please submit your bugs, requests and feedback at the project’s page on Lighthouse - rbarazi.lighthouseapp.com/projects/19246/home. RDocs are available at ridaalbarazi.com/code/simply_searchable/.
Example:
If you have the following attributes in you posts table:
Post
id:integer
title:string
body:text
category_id:integer
created_at:datetime
updated_at:datetime
In your Model:
class Post < ActiveRecord::Base
has_many :comments
belongs_to :category
simply_searchable
end
This will create the following named scopes:
named_scope where_id, lambda {|value| { :conditions => ["id = ?", value] }}
named_scope where_title, lambda {|value| { :conditions => ["title like ?", "%#{value}%"] }}
named_scope where_body, lambda {|value| { :conditions => ["body like ?", "%#{value}%"] }}
named_scope where_created_at, lambda {|value| { :conditions => ["created_at = ?", value] }}
named_scope where_updated_at, lambda {|value| { :conditions => ["updated_at = ?", value] }}
named_scope where_categories, lambda {|value| { :conditions => ["category_id in (?)", [*value]] }}
named_scope where_comments, lambda {|value| { :conditions => ["comments.ids in (?)", [*value]] }}
It will also create the method ‘list’ which you can use like:
Post.list(:title => 'abc', :created_at => Date.today, :category => [1,3])
Which will return the posts that contain ‘abc’ in their title and created today from categories 1 and 3.
By default SimplySearchable list will_paginate, you can still disable it:
class Post < ActiveRecord::Base
simply_searchable :will_paginate => false
end
Or customize its settings:
class Post < ActiveRecord::Base
simply_searchable :per_page => 20
end







