gpt4 book ai didi

ruby-on-rails - 设计如何在登录后重定向到不同的页面(基于某些参数)?

转载 作者:行者123 更新时间:2023-12-03 16:07:13 25 4
gpt4 key购买 nike

在我的应用程序中,我有两个来自两个 Controller 的不同登录表单,它们都将通过 Devise::SessionsController 登录,问题是在成功登录(或失败)后,我需要重定向到特定于 Controller 的不同页面。我怎样才能做到这一点。我目前在我的 Devise::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

最佳答案

在应用程序 Controller 中

  before_filter :store_location
def store_location
unless params[:controller] == "devise/sessions"
url = #calculate the url here based on a params[:token] which you passed in
session[:user_return_to] = url
end
end

def stored_location_for(resource_or_scope)
session[:user_return_to] || super
end

def after_sign_in_path_for(resource)
stored_location_for(resource) || root_path
end

关于ruby-on-rails - 设计如何在登录后重定向到不同的页面(基于某些参数)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9835365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com