Module: Droom::Concerns::Slugged

Extended by:
ActiveSupport::Concern
Included in:
Droom::Calendar, Droom::Category, Event, EventType, Folder, Group, Venue
Defined in:
app/models/droom/concerns/slugged.rb

Instance Method Summary collapse

Instance Method Details

#ensure_presence_of_unique(column, base, skope = self.class.all) ⇒ Object



12
13
14
15
16
17
18
19
# File 'app/models/droom/concerns/slugged.rb', line 12

def ensure_presence_of_unique(column, base, skope=self.class.all)
  unless self.send "#{column}?".to_sym
    value = base
    addendum = 0
    value = "#{base}_#{addendum+=1}" while skope.find_by(column => value)
    self.send :"#{column}=", value
  end
end

#slug_from_nameObject



4
5
6
# File 'app/models/droom/concerns/slugged.rb', line 4

def slug_from_name
  ensure_presence_of_unique(:slug, name.parameterize)
end

#slug_from_name_and_yearObject



8
9
10
# File 'app/models/droom/concerns/slugged.rb', line 8

def slug_from_name_and_year
  ensure_presence_of_unique(:slug, "#{year} #{name}".parameterize)
end