Rails gem:生产中的Cancan不起作用

时间:2014-08-30 11:51:18

标签: ruby-on-rails cancancan

我正在使用cancancan ..它在开发环境中运行良好..但是一旦我在生产中得到它,该网站就像没有安装任何宝石一样工作..没有授权处理。

我无法弄清楚出了什么问题

--------------------编辑 在应用程序控制器中有

before_filter :authenticate_user!, if: :devise_controller?

rescue_from CanCan::AccessDenied do |exception|
  # Make sure we don't redirect to an HTML page
  # in API requests because this is absolutely a bad idea
  unless request.accept == 'application/json'
    flash[:error] = "Access denied."
    redirect_to root_url
  end
end

并在能力档案中

def initialize(user)
  # Define abilities for the passed in user here. For example:
  #
  user ||= User.new # guest user (not logged in)
  if user.admin?
    can :manage, :all
  else
    can :index, Book
    can :index, Category 
  end
end

0 个答案:

没有答案