2017-03-01 47 views
0

在Ruby on Rails 4中,我的一個操作失敗,因爲它重定向到nil。獲取重定向列表並找出錯誤的呼叫的最佳做法是什麼?設計after_confirmation_path_for並且零重定向錯誤

編輯: 有問題的代碼是:

class ConfirmationsController < Devise::ConfirmationsController 
    def after_confirmation_path_for(resource_name, resource) 
     redirect_to some_specific_path_helper 
    end 
end 

每當我打在設計電子郵件確認動作,這個動作失敗,關於零重定向報告。

+0

執行軌服務器日誌顯示什麼? – Sinstein

+0

這是測試派上用場的地方 – margo

+1

除非您的重定向在config/routes.rb中定義,否則不存在「重定向列表」**。如果你的重定向是在config/routes.rb中定義的,你可以運行'bundle exec rake routes'。然後,你應該看到如下內容:'named_pa​​th GET /path(.:format)redirect(301)' 如果你的重定向是在一個控制器動作中定義的(我懷疑你現在在做什麼),你不能獲取所有重定向列表。你能提供你的控制器代碼嗎?你能顯示一些日誌嗎? – Codextremist

回答

0

所以我的錯誤是,after_confirmation_path_for不是一個行動,而是一個簡單的路徑幫手。因此,在confirmation_path_for內調用重定向是不合適的,並導致此方法返回零(即沒有)。

正確使用after_confirmation_path_for是有它返回選擇的道路,就像這樣:

class ConfirmationsController < Devise::ConfirmationsController 
    def after_confirmation_path_for(resource_name, resource) 
     # just return the path, do not call redirect 
     some_specific_path_helper 
    end 
end