You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.2 KiB
37 lines
1.2 KiB
class Workshop < ActiveRecord::Base
|
|
belongs_to :conference
|
|
|
|
has_many :workshop_facilitators, :dependent => :destroy
|
|
has_many :users, :through => :workshop_facilitators
|
|
|
|
accepts_nested_attributes_for :workshop_facilitators, :reject_if => proc {|u| u[:user_id].blank?}, :allow_destroy => true
|
|
|
|
before_create :make_slug
|
|
|
|
def to_param
|
|
slug
|
|
end
|
|
|
|
private
|
|
def make_slug
|
|
if !self.slug
|
|
s = self.title.gsub(/[^a-z1-9]+/i, '-').chomp('-').gsub(/\-([A-Z])/, '\1')
|
|
if Organization.find_by(:slug => s) && self.locations && self.locations[0]
|
|
s += '-' + self.locations[0].city
|
|
if Organization.find_by(:slug => s) && locations[0].territory
|
|
s += '-' + self.locations[0].territory
|
|
end
|
|
if Organization.find_by(:slug => s)
|
|
s += '-' + self.locations[0].country
|
|
end
|
|
end
|
|
attempt = 1
|
|
ss = s
|
|
while Organization.find_by(:slug => s)
|
|
attempt += 1
|
|
s = ss + '-' + attempt
|
|
end
|
|
self.slug = s
|
|
end
|
|
end
|
|
end
|
|
|