在我的應用程序中,我有兩個來自兩個控制器的登錄表單,這兩個登錄表單都將通過Devise :: SessionsController進行簽名,問題是在成功登錄(或失敗)之後,我需要重定向到特定於控制器的不同頁面。我怎樣才能做到這一點。我現在有這在我的設計:: SessionsController,這登錄後如何重定向到不同的頁面(基於某個參數)?
class SessionsController < Devise::SessionsController
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
return sign_in_and_redirect(resource_name, resource)
end
def sign_in_and_redirect(resource_or_scope, resource=nil)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
sign_in(scope, resource) unless warden.user(scope) == resource
redirect_to dashboard_path
end
def failure
redirect_to index_path
end
end
是的,但問題是我如何提供參數after_sign_in_path_for告訴下一步該去哪裏? – Rn2dy 2012-03-23 07:26:44
比你應該創建自己的會話控制器,並在設計配置中覆蓋它,就像這樣:'devise_for:users,:controllers => {:sessions =>「users/sessions」}'。在此控制器中,您可以將可選參數傳遞給'after_sign_in_path_for',並在需要時再檢查它們。此外,您可以將會話參數傳遞給會話並在自定義'after_sign_in_path_for'中檢查會話變量,或者可以使用'Thread.current'來傳遞這個附加參數。 – Hck 2012-03-23 07:29:06
謝謝Hck,我想這個問題真的是我應該如何定義這個參數,我應該在哪裏將這個參數傳遞給after_sign_in_path,請幫助。 – Rn2dy 2012-03-23 07:35:38