Method: FriendlyId::Slugged#normalize_friendly_id
- Defined in:
- lib/friendly_id/slugged.rb
#normalize_friendly_id(value) ⇒ Object
Process the given value to make it suitable for use as a slug.
This method is not intended to be invoked directly; FriendlyId uses it internally to process strings into slugs.
However, if FriendlyId's default slug generation doesn't suit your needs, you can override this method in your model class to control exactly how slugs are generated.
Example
class Person < ActiveRecord::Base
extend FriendlyId
friendly_id :name_and_location
def name_and_location
"#{name} from #{location}"
end
# Use default slug, but upper case and with underscores
def normalize_friendly_id(string)
super.upcase.gsub("-", "_")
end
end
bob = Person.create! :name => "Bob Smith", :location => "New York City"
bob.friendly_id #=> "BOB_SMITH_FROM_NEW_YORK_CITY"
More Resources
You might want to look into Babosa[https://github.com/norman/babosa], which is the slugging library used by FriendlyId prior to version 4, which offers some specialized functionality missing from Active Support.
289 290 291 292 293 |
# File 'lib/friendly_id/slugged.rb', line 289 def normalize_friendly_id(value) value = value.to_s.parameterize value = value[0...friendly_id_config.slug_limit] if friendly_id_config.slug_limit value end |