This project is archived and is in readonly mode.
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
-
Michael Klishin (antares) January 11th, 2009 @ 05:40 PM
- State changed from new to wontfix
Strongly against this magical feature. Params verification is important part of the work controller/models do explicitly, and adding even more magic to AR is not worth it for me. It is already the most magical piece of Ruby code out there.
If someone disagrees, reopen.
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>