Rails Friendly_Id on Heroku, Heroku not updating slugs

丶灬走出姿态 提交于 2019-12-01 20:36:00

And of course, it's always something silly. I'm really not sure how I missed this:

This piece of code:

def should_generate_new_friendly_id?
  new_record?
end

Which is there to stop new slugs being made if the name is changed, was also stopping it updating previous posts.

I solved the issue by commenting this out, pushing, running the Heroku console & then User.find_each(&:save) worked just fine, I then un-commented the code & pushed to Heroku again, and everything is dandy.

Hopefully this may help someone in the future!

In my case it was history:

friendly_id :text, use: [:slugged, :history]

Had to be

friendly_id :text, use: :slugged

To make the heroku save work... I then readded the history part

I was able to fix this issue by changing my should_generate_new_friendly_id? method from

  def should_generate_new_friendly_id?
    title_changed?
  end

to

  def should_generate_new_friendly_id?
    slug.nil? || title_changed?
  end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!