Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何与葡萄一起使用CanCan?_Ruby On Rails_Ruby_Ruby On Rails 4_Cancan_Grape Api - Fatal编程技术网

Ruby on rails 如何与葡萄一起使用CanCan?

Ruby on rails 如何与葡萄一起使用CanCan?,ruby-on-rails,ruby,ruby-on-rails-4,cancan,grape-api,Ruby On Rails,Ruby,Ruby On Rails 4,Cancan,Grape Api,我想在API中使用CanCan进行授权。例如,如何使用授权方法?现在,当我尝试使用它时,它会返回以下信息: 未定义的方法“authorize!”对于#确定,授权是对ActionController::Base的添加,请参阅 您可以定义自己的辅助对象: class API < Grape::API helpers do def authorize!(*args) # you already implement current_user helper :) ::A

我想在API中使用CanCan进行授权。例如,如何使用
授权方法?现在,当我尝试使用它时,它会返回以下信息:

未定义的方法“authorize!”对于#

确定,
授权
是对
ActionController::Base
的添加,请参阅

您可以定义自己的辅助对象:

class API < Grape::API
  helpers do
   def authorize!(*args)
     # you already implement current_user helper :)
     ::Ability.new(current_user).authorize!(*args)
   end
  end
end
class-API
或者使用模块助手:
helpers CanCan::ControllerAdditions
(顺便说一句,我认为这不是个好主意)