Trying to get my app running the FriendlyId gem (version 4.0.1)
I think I’m doing this in the wrong order, but I want to strip out apostrophes before my friendly_id slug is generated when creating a new record. But I think the method normalize_friend_id is being called after the id is already generated.
I’ve added the following to my model:
class Team < ActiveRecord::Base
extend FriendlyId
friendly_id :name, :use => :slugged
def normalize_friendly_id(string)
super.gsub("\'", "")
end
end
supercalls the superclass first, meaning the friendly id is being generated then you’re running gsub on THAT result. What you really want is to override this method completely.Refer to: https://github.com/norman/friendly_id/blob/master/lib/friendly_id/slugged.rb#L244-246
your code should look like this:
or
Hope that helps