如何使用Rails和Devise重定向到不同的注销路径 [英] How i can redirect to different signout paths using Rails and Devise
本文介绍了如何使用Rails和Devise重定向到不同的注销路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用rails3和gem设计,我有两个角色管理员和客户,我想要用户
I am using rails3 and gem devise and i have two roles admin and customer and i want after user
注销管理员应重定向到不同的路径,客户应该重定向
sign out admin should redirect to different path and customer should redirect to different path
推荐答案
可以通过不同的路径
通过在sign_out路径之后使用devise方法获得所需的功能。
You can get your desired functionality by using devise method after sign_out path.
,但在应用程序助手中定义这些方法之前。
but before you define these methods in application helper.
def is_admin?(user)
admin_role = Role.find(:first, :conditions => ["name = ?", "admin"])
return user.roles.include?(admin_role)
end
def is_customer?(user)
admin_role = Role.find(:first, :conditions => ["name = ?", "customer"])
return user.roles.include?(admin_role)
end
在应用程序控制器中包含应用程序助手并定义此方法
After that include application helper in application controller and define this method
def after_sign_out_path_for(resource_or_scope)
if is_admin?(current_user)
home_path = "/admin/users/sign_in"
elsif is_customer?(current_user)
home_path = "/customer"
end
respond_to?(home_path, true) ? send(root_path) : home_path
结束
希望它会正常工作!!!
Hope it will work fine !!!
这篇关于如何使用Rails和Devise重定向到不同的注销路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文