Module: SluggableArthur
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/sluggable_arthur.rb,
lib/sluggable_arthur/version.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
Instance Method Details
#generate_slug ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sluggable_arthur.rb', line 12 def generate_slug prefix_slug = self.send(self.slug_column.to_sym).to_slug if prefix_slug.length == 0 prefix_slug = self.id.to_s end count = 1 the_slug = prefix_slug obj = self.class.find_by(slug: the_slug) while obj && obj != self the_slug = prefix_slug + '-' + count.to_s count += 1 obj = self.class.find_by(slug: the_slug) end self.slug = the_slug end |
#to_param ⇒ Object
31 32 33 |
# File 'lib/sluggable_arthur.rb', line 31 def to_param self.slug end |