Devise & Custom Rails User URLs

2019-05-20 22:09发布

问题:

I am currently using Rails 3.2.5 with the latest devise gem.

Currently users can access their profile page at... example.com/users/john-doe

I want to remove the users portion of the url, so the url would be example.com/john-doe. Is this possible with devise?

Right now in my routes file I have the following...

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

回答1:

Just add a route for it. You will probably want it to be the last one in the routes file.

Something like:

match '/:user' => "users#show", :as => :user_profile