0

I am trying to use the Friendly_id gem and it works for user edit but not user show page. On the user show page it still uses the user id instead of the user_name which is the slug. I am not sure what my mistake is thank you for all the help.

routes

class User < ApplicationRecord
  extend FriendlyId
  friendly_id :user_name, use: :slugged
end

user_controller

def edit
  @user = User.friendly.find(params[:id])
end

def show
  @user = User.friendly.find(params[:id])
end

routes

Rails.application.routes.draw do
  resources :users
end
jrocc
  • 1,274
  • 2
  • 18
  • 48

2 Answers2

1

Following the official document of friendly_id, i guessed that you missed this line: extend FriendlyId

class User < ApplicationRecord
  extend FriendlyId 
  friendly_id :user_name, use: :slugged
end
Khanh Pham
  • 2,848
  • 2
  • 28
  • 36
0

For me I solve it by removing use: :slugged

class User < ApplicationRecord
  extend FriendlyId
  friendly_id :user_name
end
nourza
  • 2,215
  • 2
  • 16
  • 42