我已經實現redirect_to_back方法在我的ApplicationController對於未在(from this blogpost簽約用戶:如果鏈接來自電子郵件(在Rails中),我可以在登錄後重定向嗎?
def redirect_to_back_or_default(default = root_url)
if request.env["HTTP_REFERER"].present? and request.env["HTTP_REFERER"] != request.env["REQUEST_URI"]
redirect_to :back
else
redirect_to dashboard_url
end
end
,我使用sessions_controller#創建:
if @user && @user.authenticate(params[:password])
sign_in(@user)
redirect_to_back_or_default(dashboard_url)
else
...
的問題是,這只是如果請求來自應用程序,則不起作用,而不是直接鏈接,如電子郵件。
是否有解決方案?
在不起作用的情況下實際發生了什麼? –
由於'HTTP_REFERER'不存在,它重定向到'dashboard_url'。 – crispychicken
那麼你希望**它在哪裏嘗試返回鏈接來自電子郵件? –