Module: Sluggable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/sluggable_pris.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#generate_slug ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sluggable_pris.rb', line 9 def generate_slug str = self.send(self.class.slug_column.to_sym) str = str.gsub /\W/, "-" str = str.downcase post = self.class.find_by slug: str count = 2 while post && post != self do checkstr = str + "-" + count.to_s post = self.class.find_by slug: checkstr count = count + 1 end if count == 2 return str else count -= 1 str = str + "-" + count.to_s return str end end |
#set_slug ⇒ Object
31 32 33 |
# File 'lib/sluggable_pris.rb', line 31 def set_slug self.slug = generate_slug end |
#to_param ⇒ Object
35 36 37 |
# File 'lib/sluggable_pris.rb', line 35 def to_param self.slug end |