Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Movie < ActiveRecord::Base
- RATINGS = %w[G PG PG-13 R NC-17] # %w[] shortcut: arrays of strings
- @@grandfathered = Date.parse('1-Nov-1968')
- validates_inclusion_of :rating, :in => RATINGS,
- :if => lambda { |m| m.release_date >= @@grandfathered }
- # another way:
- validates_inclusion_of :rating, :in => RATINGS, :unless => :grandfathered
- def grandfathered ; release_date <= @@grandfathered ; end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement