[英]How to redirect to another page after devise sign in?
First, see my routes : 首先,查看我的路线:
Rails.application.routes.draw do
require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'
devise_for :users, controllers: {
registrations: "registrations",
sessions: "sessions"
}
devise_scope :user do
authenticated :user do
root 'appointments#index', as: :authenticated_root
end
unauthenticated do
root 'sessions#new', as: :unauthenticated_root
end
match '/logout', :to => 'devise/sessions#destroy', via: :all
end
resources :appointments do
get :available_slots, on: :collection
resources :notes
resources :images, only: [:show]
end
#patch 'appointments/:id' => "appointments#update_status", as: :update_status
match 'appointments/:id/update_status' => "appointments#update_status", :via => :post
match 'appointments/:id/visited_patient_appointment' => "appointments#visited_patient_appointment", :via => :post
get 'archive' => "appointments#archive"
end
Now, how to redirect to appointments_path after user sign in? 现在,如何在用户登录后重定向到约会路径? There is one devise method called after_sign_in_path_for(resource) which I override in Appointments Controller but still it is not working.
有一种设计方法after_sign_in_path_for(resource),我在约会控制器中对其进行了重写,但仍然无法正常工作。
You trying to override in Appointments Controller which is wrong, it will be
sessions_controller.rb
orapplication_controller.rb
您尝试覆盖约会控制器中的错误,它将是
sessions_controller.rb
或application_controller.rb
Try the following in the sessions_controller.rb
or application_controller.rb
在
sessions_controller.rb
或application_controller.rb
尝试以下操作
protected
def after_sign_in_path_for(resource)
stored_location_for(resource) || appointments_path
end
If not have stored_location
then he will redirect to appointments_path
如果没有
stored_location
那么他将重定向到appointments_path
stored_location
If you need to redirect all time to the same page like appointments_path
then 如果您需要将所有时间都重定向到同一页面(例如
appointments_path
则
protected
def after_sign_in_path_for(resource)
appointments_path
end
See the Devise wiki 参见Devise Wiki
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.