osem-fcy/app/models/venue.rb
2014-06-06 19:16:39 +05:30

23 lines
798 B
Ruby

class Venue < ActiveRecord::Base
attr_accessible :name, :description, :website, :address, :photo, :lodgings_attributes
has_many :conferences
has_many :lodgings
before_create :generate_guid
has_attached_file :photo,
styles: { thumb: '100x100>', large: '300x300>' }
validates_attachment_content_type :photo,
content_type: [/jpg/, /jpeg/, /png/, /gif/],
size: { in: 0..500.kilobytes }
accepts_nested_attributes_for :lodgings, reject_if: proc { |r| r['name'].blank? },
allow_destroy: true
private
def generate_guid
begin
guid = SecureRandom.urlsafe_base64
end while Venue.where(:guid => guid).exists?
self.guid = guid
end
end