Created
January 31, 2010 01:25
-
-
Save mcurtis/290828 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Meeting < ActiveRecord::Base | |
attr_accessible :title, :start, :start_date, :start_time, :duration, :external_id, :description | |
belongs_to :user | |
validates_presence_of :title | |
validates_numericality_of :duration, :greater_than_or_equal_to => 1 | |
before_save :calculate_end_time | |
def generate_external_id | |
record = Object.new | |
while record | |
random = Array.new(6){rand 10}.join | |
record = Meeting.find(:first, :conditions => ["external_id = ?", random]) | |
end | |
return random | |
end | |
def start_date | |
@date = Date.new(self.start.year.to_i,self.start.month.to_i,self.start.day.to_i) | |
end | |
def start_time | |
@time = Time.at(self.start.time) | |
end | |
private | |
def calculate_end_time | |
self.end = self.start.advance(:hours => self.duration) | |
end | |
end | |
class User < ActiveRecord::Base | |
attr_accessible :username, :email, :password, :password_confirmation, :company, :time_zone, :is_admin, :telecon_code | |
acts_as_authentic do |c| | |
c.login_field = :email | |
end | |
has_many :meetings, :order => "start ASC" | |
validates_presence_of :username, :time_zone, :email | |
validates_uniqueness_of :email | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment