Plugins - DynaCon
Add to favoritesDynaCon - Create dynamic search conditions quick and easy
| Author: | Michael Behan aka Jabberwock (jabberwock /AT tenebrous /DOT com) |
| Copyright: | ©2007 Michael Behan |
| License: | BSD |
Note:
In production mode, you MUST call MyModel.clear_conditions before appending conditions, because of model caching.
Usage:
MyModel.add_conditions(string, args) then: MyModel.find(:all, :conditions => MyModel.dynamic_conditions)
Examples:
- User.add_conditions(‘username = ?’, ‘mbehan’)
- User.add_conditions(‘username = ? AND first_name ~* ?’, ‘mbehan’, ‘michael’)
Each consecutive call will append the new conditions you supply. You may then use this in a Model.find via:
MyModel.find(:all, :conditions => MyModel.dynamic_conditions)
Voila! That’s it :)

I'm not sure how the two are related. This plugin is to help if say you're wanting to download a CSV based on 30 different search parameters supplied by the user. They may supply 1 or they may supply 30. I don't see how with_scope would be a better choice in this situation.
Have you had a look at ActiveRecord scoping (see #with_scope)? It might be a better choice in most cases.