Module: SluggableJake
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/sluggable_jake.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#generate_slug! ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sluggable_jake.rb', line 13 def generate_slug! alt_title = self.send(self.class.slug_column.to_sym).strip.gsub(/\W/,'-').downcase alt_title.gsub!(/-+/, '-') slug = alt_title num = 0 while !!self.class.find_by(slug: slug) num += 1 slug = alt_title + '-' + num.to_s end self.slug = slug end |
#to_param ⇒ Object
9 10 11 |
# File 'lib/sluggable_jake.rb', line 9 def to_param self.slug end |