Rn2*_*2dy 5 ruby-on-rails devise
在我的应用程序中,我有两个不同的登录表单来自两个控制器,它们都将通过Devise :: SessionsController签名,问题是在成功登录(或失败)后我需要重定向到特定于控制器的不同页面.我怎样才能做到这一点.我目前在我的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
Run Code Online (Sandbox Code Playgroud)
Joh*_*mer 15
在应用程序控制器
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6914 次 |
| 最近记录: |