Plugins - DynaCon

StarAdd to favorites

DynaCon - 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 :)

Jabberwock

svn://rails.bleedingtrends.com/dyna_con

BSD

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

Searching and Queries

Tags

Comments

Add a comment
Jabberwock 20 Jun 2007

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.

Michael Schuerig 17 Jun 2007

Have you had a look at ActiveRecord scoping (see #with_scope)? It might be a better choice in most cases.

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?