Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

allow finder conditions to accept string ranges

#1733

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.

Reported by Darius · January 11th, 2009 @ 05:01 PM

State: wontfix
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Darius
  2. Michael Klishin (antares)
    Michael Klishin (antares)
    • 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.

    January 11th, 2009 @ 05:40 PM