2013-01-07 09:04:09 +01:00
|
|
|
class Venue < ActiveRecord::Base
|
2014-06-14 21:48:43 +05:30
|
|
|
attr_accessible :name, :description, :website, :address, :photo, :lodgings_attributes
|
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
|
2013-01-07 09:04:09 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def generate_guid
|
|
|
|
|
begin
|
|
|
|
|
guid = SecureRandom.urlsafe_base64
|
|
|
|
|
end while Venue.where(:guid => guid).exists?
|
|
|
|
|
self.guid = guid
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|