Plugins - Filter
Add to favoritesFilter 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
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)
Misc. Enhancements

In rails 2.1 you have to use ::Filter.new with this plugin because of the ActionController::Filters::Filter object
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!
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.