osem-fcy/app/models/venue.rb

36 lines
1.3 KiB
Ruby
Raw Normal View History

2013-01-07 09:04:09 +01:00
class Venue < ActiveRecord::Base
attr_accessible :name, :description, :website, :address, :photo, :lodgings_attributes,
:include_venue_in_splash, :include_lodgings_in_splash
2013-01-07 09:04:09 +01:00
has_many :conferences
2014-06-14 20:41:26 +05:30
has_many :lodgings
2013-01-07 09:04:09 +01:00
before_create :generate_guid
2014-06-14 18:33:39 +05:30
has_attached_file :photo,
styles: { thumb: '100x100>', large: '300x300>' }
2013-01-07 09:04:09 +01:00
2014-06-14 18:33:39 +05:30
validates_attachment_content_type :photo,
content_type: [/jpg/, /jpeg/, /png/, /gif/],
size: { in: 0..500.kilobytes }
2014-06-14 20:41:26 +05:30
accepts_nested_attributes_for :lodgings, allow_destroy: true
2014-07-21 14:27:32 +02:00
2014-08-12 16:04:24 +05:30
def venue_notify?(conference)
(self.name_changed? || self.address_changed?) &&
(!self.name.blank? && !self.address.blank?) &&
(conference.email_settings.send_on_venue_update &&
!conference.email_settings.venue_update_subject.blank? &&
conference.email_settings.venue_update_template)
end
2013-01-07 09:04:09 +01:00
private
2014-07-21 14:27:32 +02:00
# TODO: create a module to be mixed into model to perform same operation
# event.rb has same functionality which can be shared
# TODO: rename guid to UUID as guid is specifically Microsoft term
2013-01-07 09:04:09 +01:00
def generate_guid
2014-07-21 14:27:32 +02:00
loop do
@guid = SecureRandom.urlsafe_base64
2014-07-21 14:49:05 +02:00
break if !Venue.where(guid: guid).any?
2014-07-21 14:27:32 +02:00
end
self.guid = @guid
2013-01-07 09:04:09 +01:00
end
end