Integrate Releases Open Source Dynamic Query Rails Plugin, PopCrit

We have plans to release several plugins to the open source community. PopCrit is the first of these. PopCrit grew out of our need to create rails conditions dynamically at run-time, usually coupled with a form like the one below.

Dynamic Search

To cope with creating rails conditions, I’m sure you’ve had to do or seen this done before:

1
2
3
4
if @f_name.to_s.length != 0
  crit += " AND first_name like ?"
  crit_values += ["#{@f_name}%"]
end

Multiply that by 10 fields in a robust dynamic query form and your code begins to smell. We hate it too, so we created the PopCrit plugin (previously a simple library in our applications) to manage those nasty dynamic queries users love so much.

With the PopCrit plugin, you can simply use the new process_criteria_params method provided. It will take your forms parameters and convert it into Rails loving conditions. Now you just have to do the following:

@cards = Infocard.find(:all, :conditions=>process_criteria_params(params[:dynamic]))

There’s more to it, so feel free to check out our repository at http://github.com/chazlett/popcrit/tree/master.

Or install it, play around, and feel free to contribute.

script/plugin install git://github.com/chazlett/popcrit.git

-Chris

Tags: , ,

Leave a Reply

Event Clipboard