Module: ActsAsSlugged
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/acts_as_slugged.rb
Overview
ActsAsSlugged
This module automatically generates slugs based on the :to_s field using a before_validation filter
Mark your model with ‘acts_as_slugged’ make sure you have a string field :slug
Defined Under Namespace
Modules: Base, ClassMethods, FinderMethods
Instance Method Summary collapse
-
#build_slug ⇒ Object
Instance Methods.
- #to_param ⇒ Object
Instance Method Details
#build_slug ⇒ Object
Instance Methods
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/concerns/acts_as_slugged.rb', line 53 def build_slug slug = to_s.parameterize.downcase[0, 250] if self.class.excluded_slugs.include?(slug) slug = "#{slug}-#{self.class.name.demodulize.parameterize}" end if (count = self.class.where(slug: slug).count) > 0 slug = "#{slug}-#{count+1}" end slug end |
#to_param ⇒ Object
67 68 69 |
# File 'app/models/concerns/acts_as_slugged.rb', line 67 def to_param slug_was || slug end |