狂欢管理员授权

时间:2012-04-15 05:56:25

标签: ruby-on-rails ruby-on-rails-3 authorization cancan spree

以下代码中的authorize! :admin, model行是什么意思?我无法在代码中的任何位置找到:admin操作。这类似于:manage选项吗?

spree_auth-1.0.3/app/controllers/spree/admin/admin_controller_decorator.rb:

require File.expand_path('../../base_controller_decorator', __FILE__)
Spree::Admin::BaseController.class_eval do
  before_filter :authorize_admin

  def authorize_admin
    begin
      model = model_class
    rescue
      model = Object
    end
    authorize! :admin, model
    authorize! params[:action].to_sym, model
  end

  protected
    def model_class
      "Spree::#{controller_name.classify}".constantize
    end
end

1 个答案:

答案 0 :(得分:2)

该方法来自Cancan gem。它用于确保current_user有权在任何继承自Spree::Admin::BaseController.的控制器中执行操作