Skip to content

Instantly share code, notes, and snippets.

@caius
Forked from djgraham/option.rb
Created March 31, 2010 12:33
Show Gist options
  • Save caius/350251 to your computer and use it in GitHub Desktop.
Save caius/350251 to your computer and use it in GitHub Desktop.
class Option < ActiveRecord::Base
attr_accessor :view_type, :comments_count, :expires_at_date, :expires_at_time
before_save :set_expires_at
after_save :set_reference, :set_default_room_allocation_name, :set_room_allocation_dates
private
def set_reference
self[:reference] = "OPT%05d" % id
create_or_update_without_callbacks
end
def set_expires_at
if self.new_record?
self.expires_at = Time.now.tomorrow.beginning_of_day + 12.hours
else
if (expires_at_date.present? || expires_at_time.present?)
self.expires_at = Time.parse("#{expires_at_date} #{expires_at_time}")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment