McL*_*boc 6 devise ruby-on-rails-3
在 Devise 的早期版本 (3.2) 中,可以访问刚刚在方法中注销的用户after_sign_out_path_for(resource),并根据该用户的任何给定属性进行重定向。
在 Devise 3.4 中,该方法after_sign_out_path_for(resource_or_scope)仅接收类名作为参数的符号resource_or_scope,即:user在我的例子中。
是否有另一种方法可以根据用户模型中的属性值在注销后重定向给定用户?
澄清一下:我不打算仅仅为了这个工作而创建不同的用户类。
小智 2
I had the exactly the same problem a while ago, and i couldn't found a way of doing it in a clean way. So to resolve that i just made a simple override to devise SessionsController in which i would save the desired attribute in session before Devise erased it:
class SessionsController < Devise::SessionsController
def sign_out
company_slug = session[:company_slug]
super
session[:company_slug] = company_slug
end
end
Run Code Online (Sandbox Code Playgroud)
And then on my after_sign_out_path_for i could do something like this:
def after_sign_out_path_for(resource_or_scope)
if session[:company_slug] == 'something'
something_path
end
end
Run Code Online (Sandbox Code Playgroud)
Of Course you don`t really need to override signout method, you could simply use
| 归档时间: |
|
| 查看次数: |
4546 次 |
| 最近记录: |