Sylar
Sylar

Reputation: 12072

Replace resource user_id with something else

I'd like to use something like domain.com/users/foo instead of the routes looking like /users/user_id/

Fair enough you could do get "/users/:name/..... but I am using nested resource:

  devise_for :users, :controllers => { omniauth_callbacks: 'omniauth_callbacks' }

  resources :users do
    resource :profile
    resources :supports do
      post :interest
    end
  end

Is there a way to change the resource users/user_id to users/firstname?

Upvotes: 0

Views: 50

Answers (1)

Pardeep Saini
Pardeep Saini

Reputation: 2102

for this you can use friendly_id gem or you can define to_param method in your user model.

def to_param
  "#{name}"
end

Upvotes: 2

Related Questions