Module: Slug::SlugInstanceMethods
- Defined in:
- lib/slug/slug.rb
Instance Method Summary collapse
-
#reset_slug ⇒ Object
Overwrite existing slug based on current contents of source column.
-
#set_slug(opts = {}) ⇒ Object
Sets the slug.
-
#to_param ⇒ Object
Overrides to_param to return the model’s slug.
Instance Method Details
#reset_slug ⇒ Object
Overwrite existing slug based on current contents of source column.
62 63 64 |
# File 'lib/slug/slug.rb', line 62 def reset_slug set_slug(:force => true) end |
#set_slug(opts = {}) ⇒ Object
Sets the slug. Called before create. By default, set_slug won’t change slug if one already exists. Pass :force => true to overwrite.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/slug/slug.rb', line 47 def set_slug(opts={}) validate_slug_columns return if self[self.slug_column].present? && !opts[:force] self[self.slug_column] = normalize_slug(self.send(self.slug_source)) # if normalize_slug returned a blank string, try the generic_default handling if generic_default && self[self.slug_column].blank? self[self.slug_column] = self.class.to_s.demodulize.underscore.dasherize end assign_slug_sequence if self.changed_attributes.include?(self.slug_column) end |
#to_param ⇒ Object
Overrides to_param to return the model’s slug.
67 68 69 |
# File 'lib/slug/slug.rb', line 67 def to_param self[self.slug_column] end |