[英]How to redirect to another page after devise sign in?
首先,查看我的路線:
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
現在,如何在用戶登錄后重定向到約會路徑? 有一種設計方法after_sign_in_path_for(resource),我在約會控制器中對其進行了重寫,但仍然無法正常工作。
您嘗試覆蓋約會控制器中的錯誤,它將是
sessions_controller.rb
或application_controller.rb
在sessions_controller.rb
或application_controller.rb
嘗試以下操作
protected
def after_sign_in_path_for(resource)
stored_location_for(resource) || appointments_path
end
如果沒有stored_location
那么他將重定向到appointments_path
stored_location
如果您需要將所有時間都重定向到同一頁面(例如appointments_path
則
protected
def after_sign_in_path_for(resource)
appointments_path
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.