0

I just add friendly_id to beautify my urls.

i get an error

      Couldn't find User with 'id'={:id=>"foo"}

Here is my setup

User.rb

class User < ApplicationRecord

 extend FriendlyId
 friendly_id :last_name, use: %i[slugged finders]

Users_controller.rb

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

I added this to my user table

add_column :users, :slug,                   :string
add_index :users,  :slug,                   unique: true

And the CreateFriendlyIdSlugs table has been correctly generated

i'm very in trouble with this issue, i'v red all the documentation and i can't see where my code fail

thx for helping

Che
  • 112
  • 9

2 Answers2

2

You can either use:

User.friendly.find(params[:id])

or

User.friendly.find_by(id: params[:id])

this #find_by can take hash as an input in case you are using hash params.

Ranjan
  • 96
  • 2
  • 9
0

The problem was how i call the params in my find

the answser is

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

instead of

@user = User.friendly.find(id: params[:id])
Che
  • 112
  • 9