Plugins - Filter

StarAdd to favorites

Filter let you specify common filtering options, in order to generate a filtered condition, useful for filtering from request params.

Example usage:

   filter = Filter.new
   filter.multiple types, :type_id

   people = People.find(:all, :conditions => filter.conditions)

   Generates: SELECT * FROM people WHERE (type_id IN (1,2))

   filter.equal type, :type_id

   Generates: SELECT * FROM people WHERE (type_id = 1)

Is very beautifull when you whant to add multiple conditions if other (conditions) are verified like:

   conditions = Filter.new
   conditions.great params[:type][:id], :type_id unless params[:type][:id].blank?
   conditions.equal params[:model][:id], :model_id unless params[:model][:id].blank?

   MyModel.find(:all, :conditions => conditions)

Code originally created by Divoxx who I give my special Thanks Code edited by http://blog.lipsiasoft.com

Davide D'Agostino (DAddYE)

http://blog.lipsiasoft.com/articles/2007/06/05/filtrare-i-risultati-in-modo-agile-con-ruby-on-rails

http://lipsiasoft.googlecode.com/svn/trunk/filter

Rails' (MIT)

  • Currently 4.9/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Misc. Enhancements

Tags

Comments

Add a comment
pj 19 Aug 2008

In rails 2.1 you have to use ::Filter.new with this plugin because of the ActionController::Filters::Filter object

DAddYE 28 Dec 2007

Thanks Andreas, sorry but I see now your comment, yes I can do what you say in the next version!

thanks so much for your feedback!

Andreas Roedl 24 Aug 2007

Would you mind to add this? <pre> # Defines a filtering that checks for not equality. # # Example: # @filter = Filter.new # @filter.isnot params[:id], 'an_id' def isnot(key, filtered) key = key.to_s @filters << ["#{filtered} != ?", key] unless key.nil? || key.empty? end </pre>

Don't know if the formatting works. If not: it is a "!=" operator/filter.

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?