Module: SluggableAnt
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/sluggable_ant.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#generate_slug! ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sluggable_ant.rb', line 23 def generate_slug! slug = self.send(self.slug_field).downcase .gsub(/\W|\_/, '-').gsub(/[\-]+/, '-') .gsub(/^[\-]+/, '').gsub(/[\-]+$/, '') i = 1 while !!self.class.where.not(id: self.id).find_by(slug: slug) do i == 1 ? slug += '-1' : slug = slug.split('-')[0..-2].join('-') + "-#{i}" i += 1 end self.slug = slug end |
#to_param ⇒ Object
19 20 21 |
# File 'lib/sluggable_ant.rb', line 19 def to_param self.slug end |