我有一个使用devise,cancan和rolify的应用程序,可以在登录时重定向到特定于其角色的页面。我想弄清楚的是我如何在应用程序的其他地方链接到相同的路径,而不仅仅是作为重定向?
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_path, :alert => exception.message
end
def after_sign_in_path_for(resource)
case current_user.roles.first.name
when 'admin'
users_path
when 'yin'
content_yin_path
when 'yang'
content_yang_path
when 'yin_yang_lite'
content_yin_yang_lite_path
when 'yin_yang_pro'
content_yin_yang_pro_path
else
root_path
end
end
end
基本上,我正在寻找如何到达current_user =&gt; role =&gt; path或current_user_role_path
答案 0 :(得分:0)
您可以使用控制器中的helper_method
宏定义任何控制器方法,以充当辅助方法。对于你的情况:
ApplicationController
helper_method :after_sign_in_path_for