Module: Sluggable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/sluggable_tim_jan15.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#add_slug ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sluggable_tim_jan15.rb', line 18 def add_slug temp_slug = slug_string(self.send(name_key)) count = self.class.all.map{|member| member.send(name_key)}.count{|title| slug_string(title) == temp_slug} if count == 0 self.slug = temp_slug else self.slug = temp_slug + '-' + (count + 1).to_s end end |
#slug_string(str) ⇒ Object
13 14 15 16 |
# File 'lib/sluggable_tim_jan15.rb', line 13 def slug_string(str) str = str.gsub(/[^0-9a-z]/i,'-').downcase str = str.gsub(/-+/, '-') end |
#to_param ⇒ Object
9 10 11 |
# File 'lib/sluggable_tim_jan15.rb', line 9 def to_param self.slug end |