konduri subrahmanyam
Joined: 12 May 2011 Posts: 88
|
Posted: Sat Feb 18, 2012 6:05 am Post subject: rd_searchlogic gem for search using conditions on column |
|
|
Hi,
In rails 3, we can use "rd_searchlogic" gem for making search using conditions on column.
Generally, we will find data in rails as "Model.find() or Model.find_by_column or Model.where()".
But, using the "rd_searchlogic" gem, we can find the records searchlogics as follows:
1) Adding gem to Gemfile:
gem 'rd_searchlogic', :require => 'searchlogic', :git => 'git://github.com/railsdog/searchlogic.git'
2) Using gem:
For example I have taken the "Post" model and "name:string, title:string, content:text" as fields of that model.
Now, we can call methods on "Post" as follows:
a) To find records having "title" as "rails":
@posts = Post.title_like("rails")
b) To find records having "name" ending with "ruby"
@posts = Post.name_ends_with("ruby")
c) To find records having "content" data not as null:
@posts = Post.content_not_null
d) To find records having "name" as "ruby" and having record "id" lessthan or equal to "10":
@posts = Post.name_like("ruby").id_less_than_or_equal_to(10)
And in this way, we can find the records that we need with a less effort using "rd_searchlogic" gem.
For more details refer to the following url:
https://github.com/binarylogic/searchlogic
Thanks and Regards,
K. Subrahmanyam. |
|