Reputation: 35
Using Devise 2.1.2---recently moved sign in form from dedicated sign in page to homepage. This has had a few side affects which I'm trying to figure out in the below.
My attempt at (1) is shown below. I'm guessing I should be able to do something similar with (2). Not quite sure how to best handle (3)---just delete view, override another devise controller, etc...
I have a production version of the website available at www.ninjaspeak.com if you want to view the behavior of the redirects yourself. Old user sign in page is at http://www.ninjaspeak.com/users/sign_in.
Following the instructions here: Redirect URL after sending reset password instructions on git hub to try and make it so when reset passwords instructions are sent it redirects to the home page rather than the sign in page.
I created the below passwords_controller.rb file:
class PasswordsController < Devise::PasswordsController
protected
def after_sending_reset_password_instructions_path_for(resource_name)
root_path
end
end
And have added the following line to my routes.rb file:
devise_for :users, :controllers => { :passwords => "passwords" }
When I run rake routes I get the following:
When I click the reset passwords instructions button I'm still getting redirected to the sign in page instead of the root page. Any thoughts on why this is?
Rails S output:
From the above it looks as if the devise passwords controller is still be used which explain why redirect is still going to user sign in page.
Edit
routes.rb
SampleApp::Application.routes.draw do
devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end
devise_for :users, :controllers => { :passwords => "passwords" , :confirmations => "confirmations" }
get 'users/sign_in' => redirect("/")
resources :langs do
collection do
get 'results'
end
end
root to: 'static_pages#home'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
match '/news', to: 'static_pages#news'
end
passwords_controller.rb
class PasswordsController < Devise::PasswordsController
protected
def after_sending_reset_password_instructions_path_for(resource_name)
root_path
end
end
confirmations_controller.rb
class ConfirmationsController < Devise::ConfirmationsController
protected
def after_resending_confirmation_instructions_path_for(resource_name)
root_path
end
end
rake routes:
matt@matt-desktop:~/Documents/Ruby/rails_projects/ninja_speak_app$ rake routes
users_sign_out GET /users/sign_out(.:format) devise/sessions#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
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
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
new_user_session GET /users/sign_in(.:format) devise/sessions#new
POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
POST /users/password(.:format) passwords#create
GET /users/password/new(.:format) passwords#new
GET /users/password/edit(.:format) passwords#edit
PUT /users/password(.:format) passwords#update
GET /users/cancel(.:format) devise/registrations#cancel
POST /users(.:format) devise/registrations#create
GET /users/sign_up(.:format) devise/registrations#new
GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
POST /users/confirmation(.:format) confirmations#create
GET /users/confirmation/new(.:format) confirmations#new
GET /users/confirmation(.:format) confirmations#show
users_sign_in GET /users/sign_in(.:format) :controller#:action
results_langs GET /langs/results(.:format) langs#results
langs GET /langs(.:format) langs#index
POST /langs(.:format) langs#create
new_lang GET /langs/new(.:format) langs#new
edit_lang GET /langs/:id/edit(.:format) langs#edit
lang GET /langs/:id(.:format) langs#show
PUT /langs/:id(.:format) langs#update
DELETE /langs/:id(.:format) langs#destroy
root / static_pages#home
about /about(.:format) static_pages#about
contact /contact(.:format) static_pages#contact
news /news(.:format) static_pages#news
Upvotes: 1
Views: 3391
Reputation: 8122
- How to change redirect on reset password instructions to go to home page, not user sign in page.
just put this in your passwords
controller
protected
def after_sending_reset_password_instructions_path_for(resource_name)
root_path
end
- How to change redirect on resend confirmation instructions to go to home page, not user sign in page.
create new confirmations_controller.rb
and put this
class ConfirmationsController < Devise::ConfirmationsController
protected
def after_resending_confirmation_instructions_path_for(resource_name)
root_path
end
end
and in routes
devise_for :users, :controllers => { :passwords => "passwords" , :confirmations => "confirmations" }
- How to make it so users can no longer access users/sign_in page
Simple trick is to redirect the user to the home page since your website is in production. remove the path might cause some problem so best is to do this
get 'users/sign_in' => redirect("/")
If all you want to signin in root page, you could have used this
root :to => "devise/sessions#new"
you have to remove this line from route.rb
file
devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end
devise_for :users, :controllers => { :passwords => "passwords" , :confirmations => "confirmations" }
get 'users/sign_in' => redirect("/")
and add this
get 'users/sign_in' => redirect("/")
get '/users/sign_out' => 'devise/sessions#destroy'
devise_for :users, :controllers => { :passwords => "passwords" , :confirmations => "confirmations" }
Upvotes: 4