class Rsvp < ActiveRecord::Base include InputSanitization belongs_to :account belongs_to :event validates_presence_of :guest_count validates_presence_of :status validate do |rsvp| if ['http://', 'href='].any? { |x| rsvp.comment.to_s.include?(x) } && rsvp.account.created_on > 1.hour.ago rsvp.errors.add_to_base("To prevent automated spam, " + "your account must have been registered for more " + "than one hour to post a link in the RSVP comment " + "(hint: come back in an hour to post the link).") end end def Rsvp.match(event, account) return nil if account.nil? find :first, :conditions => ['event_id = ? AND account_id = ?', event.id, account.id] end def Rsvp.gather(event, status) find :all, :conditions => ['event_id = ? AND status = ?', event.id, status] end def owner?(user) self.account == user end end