當我到localhost:3000/users/sign_in時,我被重定向到用戶#顯示錯誤(因爲沒有當前用戶)而不是符號在頁面中。通過我所能想到的一切,這不應該發生,但它是。如果我點擊指向new_user_session_path的鏈接,或者直接輸入URI,我都會被重定向。RoR,Devise:路由以重定向到用戶登錄#show
我已經通過我的路線看過重複項,並且已清除會話和緩存。老實說,整個設計界面非常簡單,我不確定還有什麼要檢查。而且這很有效,所以很明顯有些事情發生了變化。
還有什麼可能會出錯?
耙路線
# output from rake:routes
# there are no other routes for this GET path
new_user_session GET /users/sign_in(.:format) devise/sessions#new
的routes.rb
#config/routes.rb
resources :users
devise_for :users
控制器
#app/controllers/user_controller.rb
before_action :confirm_signed_in
def confirm_signed_in
unless user_signed_in?
initiate_return_to_last_successful
flash.now[:notice] = 'Please sign in.'
redirect_to new_user_session_path
end
end
注:我最近WA試圖修改設計註冊控制器創建操作。我不確定是否會導致這種情況,但我已經退出了與之相關的所有更改(我相信,檢查了三次)。
設計確實有一個before_action,'authenticate_user!',它可以代替你的'confirm_signed_in'。 [檢查文檔在這裏](https://github.com/plataformatec/devise#controller-filters-and-helpers) –
謝謝。由於我想修改它,我只是自己做了。 – steel