27

I want to completely disable the routes /users/sign_in for get and post.

I was able to successfully override them using the following:

  devise_for :users do
      get "/admin" => "devise/sessions#new", :as => :new_user_session
      post "/admin" => "devise/sessions#create", :as => :user_session
  end

And when I run rake routes I see the following:

    new_user_session GET    /admin(.:format)                {:controller=>"devise/sessions", :action=>"new"}
    user_session     POST   /admin(.:format)                {:controller=>"devise/sessions", :action=>"create"}
    new_user_session GET    /users/sign_in(.:format)        {:action=>"new", :controller=>"devise/sessions"}
                     POST   /users/sign_in(.:format)        {:action=>"create", :controller=>"devise/sessions"}

I can access the sign in from /admin as well as from /users/sign_in. But I want to completely remove the last two rows, is it possible?

I tried some different combinations from the documentation which seems to do it but it also overrides some useful ones, like the password/new and password/edit routes.

JohnDel
  • 2,092
  • 8
  • 35
  • 64

4 Answers4

27

Katz's solution no longer works as noted by Cirulli.

Try the following.

devise_for :users, :skip => [:sessions]

as :user do
    get "/admin" => "devise/sessions#new", :as => :new_user_session
    post "/admin" => "devise/sessions#create", :as => :user_session
end
Rob Olendorf
  • 561
  • 5
  • 9
23

You can achieve this by using the :skip option to devise_for:

devise_for :users, :skip => [:sessions] do
    get "/admin" => "devise/sessions#new", :as => :new_user_session
    post "/admin" => "devise/sessions#create", :as => :user_session
end

When I run rake routes after that, I get just:

    new_user_session GET    /admin(.:format)               {:controller=>"devise/sessions", :action=>"new"}
        user_session POST   /admin(.:format)               {:controller=>"devise/sessions", :action=>"create"}
Yehuda Katz
  • 28,535
  • 12
  • 89
  • 91
  • Thank you so much for answering my question! I also added this delete "/logout" => "devise/sessions#destroy", :as => :destroy_user_session for the logout and the functionality is exactly what I wanted. :) – JohnDel Dec 10 '11 at 08:39
  • 4
    Doesn't seem to work anymore. `devise_for` looks like it's ignoring the block. – kettlepot Sep 22 '13 at 21:10
5

Here it is

devise_for :users, skip: [:sessions,:registrations], controllers: {
  omniauth_callbacks: "users/omniauth_callbacks"
}
Tim Kozak
  • 4,026
  • 39
  • 44
3

when you skip sessions controller, you most add destroy action to your custom routes too:

as :user do
    get "/admin" => "devise/sessions#new", :as => :new_user_session
    post "/admin" => "devise/sessions#create", :as => :user_session
    delete "/logout" => "devise/sessions#destroy", :as => :destroy_user_session
end
Zakaria
  • 983
  • 15
  • 24