Am i doing something wrong ? on Record update, slug is not being updated.
class Company < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: [:slugged, :finders]
def should_generate_new_friendly_id?
true
end
I'm using:
friendly_id (5.0.4)
Rails 4.1.7
ruby 2.1.3p242 (2014-09-19 revision 47630)
This is how I'm trying in terminal:
c = Company.last
c.slug = nil
c.name = "testing abb"
c.save
c.reload
c.slug // nil
c.name // testing abb
at the time of create: it inserts the slug but doesnt update on record update. any idea ?
Add :history
to friendly_id :name, use: %i(slugged finders)
:
friendly_id :name, use: %i(slugged history finders)
and override should_generate_new_friendly_id
method to meet your needs:
def should_generate_new_friendly_id? #will change the slug if the name changed
name_changed?
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With