Module: SluggableCgeb
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/sluggable_cgeb.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#generate_slug ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sluggable_cgeb.rb', line 18 def generate_slug the_slug = to_slug obj = obj_lookup(to_slug) count = 2 if obj && obj != self the_slug = the_slug + "-" + count.to_s obj = obj_lookup(the_slug) end while obj && obj != self count += 1 the_slug[-1] = count.to_s obj = obj_lookup(the_slug) end self.slug = the_slug end |
#obj_lookup(str) ⇒ Object
9 10 11 |
# File 'lib/sluggable_cgeb.rb', line 9 def obj_lookup(str) self.class.find_by slug: str end |
#to_param ⇒ Object
34 35 36 |
# File 'lib/sluggable_cgeb.rb', line 34 def to_param self.slug end |
#to_slug ⇒ Object
13 14 15 16 |
# File 'lib/sluggable_cgeb.rb', line 13 def to_slug str = self.send(self.class.slug_column.to_sym).downcase.gsub(/[^0-9a-zA-Z]/, "-") str = str.gsub(/-+/, "-") end |