Class: Slug
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Slug
- Defined in:
- app/models/slug.rb
Overview
Stores slugs used to prettify URLs. For more information, see the Slugalicious mixin.
As new slugs are created, old ones are marked as inactive and kept around for redirect purposes. Once a slug is old enough, it is deleted and its value can be used for new records (no longer redirects).
Associations
| | | |:————|:————————————–| | ‘sluggable` | The record that this slug references. |
Properties
| | | |:———|:————————————————————————————————-| | ‘slug` | The slug, lowercased and normalized. Slugs must be unique to their `sluggable_type` and `scope`. | | `active` | Whether this is the most recently generated slug for the sluggable. | | `scope` | Freeform data scoping this slug to a certain subset of records within the model. |
Instance Method Summary collapse
-
#activate! ⇒ Object
Marks a slug as active and deactivates all other slugs assigned to the record.
Instance Method Details
#activate! ⇒ Object
Marks a slug as active and deactivates all other slugs assigned to the record.
59 60 61 62 63 64 |
# File 'app/models/slug.rb', line 59 def activate! self.class.transaction do Slug.for(sluggable_type, sluggable_id).update_all(active: false) update_column :active, true end end |