Devise routes to only use custom sign in page
Posted
by
eblume
on Stack Overflow
See other posts from Stack Overflow
or by eblume
Published on 2012-06-14T17:48:02Z
Indexed on
2012/06/16
3:16 UTC
Read the original article
Hit count: 309
ruby-on-rails-3
|devise
I am trying to learn Devise and seem to have hit a problem that is nearly the same as many, many questions here on SO but just slightly different enough that I am not getting much traction following those questions' threads.
I have a very simple application. Users can sign in and sign out (and also the devise 'forgot password' stuff is enabled - I am not concerned about it at this time) and that is it. They can't register, they can't edit their profile other than to change their password, they can't do anything except sign in and sign out. (Account creation will, for now, be handled manually at the command line.)
I would vastly prefer that the only page that users can log in from was "/" (root_path
). I already have it working where you can log in from "/", and that is great. The problem I am having is that if you type in your user/password combination incorrectly from the root_path login page, it automatically sends you to the Devise sign-in page to continue trying to sign in. How can I make Devise redirect to root_path on sign-in failure?
Here are my routes - they are probably not optimal or correctly configured and I would appreciate pointers on fixing them:
root to: "core_pages#splash"
devise_for :users, skip: [:sessions]
as :user do
# get 'signin' => 'devise/sessions#new', as: :new_user_session
post 'signin' => 'devise/sessions#create', as: :user_session
delete 'signout' => 'devise/sessions#destroy', as: :destroy_user_session,
via: Devise.mappings[:user].sign_out_via
end
match '/home' => 'core_pages#home'
Note the commented-out 'get signin' line. The system works without this line but, surprisingly (to me), "GET /signin" results in a HTTP 400 (OK) response and renders the Devise login template. I would prefer it return some sort of 'invalid request' or just silently redirect the user to root_path
.
Running rake routes
on these routes gives:
root / core_pages#splash
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
user_session POST /signin(.:format) devise/sessions#create
destroy_user_session DELETE /signout(.:format) devise/sessions#destroy
home /home(.:format) core_pages#home
Thanks!
© Stack Overflow or respective owner