Skip to content

Instantly share code, notes, and snippets.

@cherring
Created May 26, 2009 03:41
Show Gist options
  • Save cherring/117876 to your computer and use it in GitHub Desktop.
Save cherring/117876 to your computer and use it in GitHub Desktop.
@@valid_fields = %w(fields in here)
named_scope :between, lambda{ |start_date, end_date, field_name|
 field = (@@valid_fields.include?(field_name)) ? (field_name) : raise (ActiveRecord::StatementInvalid)
 {  :conditions => ["#{field} >= ? AND #{field} <= ?",  start_date, end_date]}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment