This repository has been archived on 2020-01-20. You can view files and clone it, but cannot push or open issues or pull requests.
evoresa/app/models/event.rb

26 lines
634 B
Ruby
Raw Normal View History

class Event < ActiveRecord::Base
TAG_RE = /\[[^]]+\]/
belongs_to :item
has_many :bookings
validates_presence_of :title, :message => "Le titre ne peut pas être vide"
validates_length_of :title, :within => 4...140,
:message => "Le titre doit faire entre 4 et 140 caractères"
def generate_color
digest = Digest::MD5.hexdigest(title =~ TAG_RE ? $~.to_s : self.title)
self.color = "##{digest[0...6]}"
end
def upcoming_bookings
self.bookings.
find(:all, :conditions => ['start_at >= ?', Date.today.at_midnight])
end
def anchor
'event-%s' % id.to_s(16)
end
end