module Sluggable

Public Instance Methods

generate_slug() click to toggle source
# 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() click to toggle source
# File lib/sluggable_pris.rb, line 31
def set_slug
   self.slug = generate_slug
end
to_param() click to toggle source
# File lib/sluggable_pris.rb, line 35
def to_param
    self.slug
end