0

I'm running a Rails 5.0.6 app with Friendly ID 5.2.4 and everything works fine except that after some time (sometimes a few hours, sometimes a few days) the friendly ids are not working anymore (instead of /username/slug-of-user-post it will become e.g. /4/23). A simple cap production deploy:restart fixes it.

Did anyone experience this kind of problem? Googled quite a bit but no luck.

Model:

def slug_candidates
  %i[title title_and_sequence]
end

def title_and_sequence
  slug = title.parameterize
  sequence = posts.where('slug LIKE ?', "#{slug}-%").count + 1
  "#{slug}-#{sequence}"
end

routes.rb: get '/:user_id/:id' => 'posts#show', as: :user_post

Controller:

def show
  @user = User.friendly.find params[:user_id]
  @post = @user.posts.friendly.find params[:id]

  render :show
end
Cojones
  • 2,930
  • 4
  • 29
  • 41

0 Answers0