I've set up the friendly_id gem, following along to the RailsCasts Screencast on it. Locally this works brilliantly, I installed it, ran through User.find_each(&:save)
which successfully updated the slug field on each of the existing users and all was fine.
I have now pushed this to Heroku, and although it works fine for any new members that are added, Heroku isn't updating the user slug for me for already existing Users.
Running heroku run console
and then User.find_each(&:save)
just does nothing:
irb(main):001:0> User.find_each(&:save)
User Load (20.2ms) SELECT "users".* FROM "users" WHERE ("users"."id" >= 0) ORDER BY "users"."id" ASC LIMIT 1000
(23.6ms) BEGIN
(2.0ms) COMMIT
(13.6ms) BEGIN
(21.1ms) COMMIT
=> nil
The relevant code in models/user.rb
is:
extend FriendlyId
friendly_id :name, use: :slugged
def should_generate_new_friendly_id?
new_record?
end
And I've run all DB migrations on Heroku and they went fine. I checked and the users
table does have a slug
field, but it's empty and I'm not sure where I'm going wrong here. If anyone happens to have come across this before, any advice would be much appreciated. Thank you.