Question

I am trying to change my urls from whatever.com/users/1 to whatever.com/users/jamie.Surname or whatever.com/users/jamie-Surname

I would quite like to eventually change to whatever.com/jamie.surname or whatever.com/jamie-surname but I thought it would be best to start of simple.

So I installed the friendly_id gem, starting simple I tried to just have it route to my first name with;

class User < ActiveRecord::Base
      extend FriendlyId
      friendly_id :first_name

However when I try to go to the url I am getting the error;

ActiveRecord::RecordNotFound in UsersController#show

Couldn't find User without an ID

Application Trace | Framework Trace | Full Trace app/controllers/users_controller.rb:22:in `show'

Request Parameters: {"id"=>"jamie"}

This line is the method in my users_controller where its throwing up the error

def show
    @user = User.find(params[:id])
        respond_to do |format|
        format.html 
        format.json { render json: @user }
    end
end

I can't seem to figure out a way to fix this.

Any help or suggestions/pushes in the right direction would be much appreciated.

Was it helpful?

Solution

This asciicast may help you -

http://railscasts.com/episodes/314-pretty-urls-with-friendlyid?view=asciicast

Also note that it is important to note that which FriendlyId version you are using.

Check this for issues:

https://github.com/norman/friendly_id/issues/146

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top