Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 25th, 2012  |  syntax: None  |  size: 0.42 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. =begin
  2.  'frozen' value for end_at in scope :active
  3.  The same frozen value is propogated to :national scope!  
  4.  The Time.now will be set to the first time the scope is evaluated.
  5.  This is explained at http://api.rubyonrails.org/classes/ActiveRecord/NamedScope/ClassMethods.html
  6.  
  7.  * NON-WORKING SOLUTION *
  8. =end
  9.  
  10. class Something
  11.  scope :active, where('end_at > ?', Time.now)
  12.  scope :national, where(:is_national => true).active
  13. end