This project is archived and is in readonly mode.

#1733 ✓wontfix
Darius

allow finder conditions to accept string ranges

Reported by Darius | January 11th, 2009 @ 05:01 PM | in 2.x

For search forms, it is desireable to use a simple syntax for searching ranges.

In a view, I would like to be able to f.select :age, ["18..21","21..28","25..35","35..108"].map{|a|[a,a]}

and in the controller i would LIKE: Person.find(:all, :conditions=>{:age=>params[:person][:age]})

vs (I currently do): Person.find(:all, :conditions=>{:age=>extract_age_range(params[:person][:age])}) def extract_age_range(string); Range.new( ...stuff...) end

To pass ranges of this form through to the finders is messy; I either need to hack rails AR::Base, or alternatively add a controller method to match and translate these strings into ranges.

Making finder ranges(from some string convention) default supports restful design, and the overhead on finders is low. (an iteration of matching through the conditions hash)

This is my first patch, so I'm looking for feedback. Should this actually be a gem? Can do. Is my testing off-base? Happy to change.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages