ruby-on-railsdeviseroutes

Can I use "devise_for", with "only" and "excepted"?


I'm building a Rails website, and setting up the devise routes. So far, I have no trouble and everything works. However, since the website is divided between the administration and the visitor place, I would like the user to be able to edit his profile from a path that looks like /admin/users/1/edit and sign in/out from /user/sign_in or user/sign_out (without the admin prefixe).

So far, I managed to do either with or without the prefix, but not both at the same time.

Here is the relevant part of my route file:

devise_for :users, only: %w['session#new session#destroy']
get '/admin' => 'home#admin', as: :admin

authenticate :user do
  scope '/admin' do
    resource :basics
    resources :portfolios
    resources :articles
    devise_for :users, excepted: %w['sessions#new session#destroy']
  end
end

And here is the result of rake routes:

new_user_session GET    /admin/users/sign_in(.:format)       devise/sessions#new
            user_session POST   /admin/users/sign_in(.:format)       devise/sessions#create
    destroy_user_session DELETE /admin/users/sign_out(.:format)      devise/sessions#destroy
       new_user_password GET    /admin/users/password/new(.:format)  devise/passwords#new
      edit_user_password GET    /admin/users/password/edit(.:format) devise/passwords#edit
           user_password PATCH  /admin/users/password(.:format)      devise/passwords#update
                         PUT    /admin/users/password(.:format)      devise/passwords#update
                         POST   /admin/users/password(.:format)      devise/passwords#create
cancel_user_registration GET    /admin/users/cancel(.:format)        devise/registrations#cancel
   new_user_registration GET    /admin/users/sign_up(.:format)       devise/registrations#new
  edit_user_registration GET    /admin/users/edit(.:format)          devise/registrations#edit
       user_registration PATCH  /admin/users(.:format)               devise/registrations#update
                         PUT    /admin/users(.:format)               devise/registrations#update
                         DELETE /admin/users(.:format)               devise/registrations#destroy
                         POST   /admin/users(.:format)               devise/registrations#create

How can do this?

Thank you in advance


Solution

  • I believe it may just be a typo, but try changing:

    devise_for :users, excepted: %w[sessions#new session#destroy]
    

    to:

    devise_for :users, except: %w[sessions#new session#destroy]