2014-06-25 55 views
1

當我到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試圖修改設計註冊控制器創建操作。我不確定是否會導致這種情況,但我已經退出了與之相關的所有更改(我相信,檢查了三次)。

+0

設計確實有一個before_action,'authenticate_user!',它可以代替你的'confirm_signed_in'。 [檢查文檔在這裏](https://github.com/plataformatec/devise#controller-filters-and-helpers) –

+0

謝謝。由於我想修改它,我只是自己做了。 – steel

回答

3

您需要切換這兩條線。文件頂部的路由優先,所以問題是使用路由模式匹配的資源。

這條路線,由resources方法生成,在/users/anything_can_go_here格式任何途徑,和替換:id將在控制器params[:id]是可用的部分相匹配。

GET '/users/:id' => 'users#show' 

這條路線,通過色器件產生的,需要被放置呼叫上面resources :users,使其具有在導軌的眼睛優先級。

GET 'users/sign_in' => 'users#sign_in' 

要解決這個問題,這

resources :users 
devise_for :users 

應該

devise_for :users 
resources :users 

要了解更多關於Ruby on Rails中的路由,檢查出this guide/tutorial

+0

就是這樣,這就解釋了它。謝謝! – steel

+0

這對我也有幫助。我與註銷鏈接有問題,但這固定它.. – whizcreed

相關問題