Skip to content

Instantly share code, notes, and snippets.

@avit
Created March 30, 2010 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avit/349501 to your computer and use it in GitHub Desktop.
Save avit/349501 to your computer and use it in GitHub Desktop.
# Before, I was overriding the initialize method to set the run_date.
# This is how I'm doing it now:
class ListingHighlight < ActiveRecord::Base
before_validation :assign_run_date
validates_presence_of :run_date, :on => :create
def run_date=( value )
write_attribute :run_date, some_date_method(value)
end
def run_date
read_attribute :run_date or write_attribute(:run_date, some_date_method)
end
protected
def assign_run_date
run_date
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment