0

我有一个使用 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 => role => path 或 current_user_role_path

4

1 回答 1

0

helper_method您可以使用控制器中的宏定义任何控制器方法以充当辅助方法。对于您的情况:

ApplicationController

helper_method :after_sign_in_path_for
于 2013-09-20T12:23:13.357 回答