我想在我的API中使用CanCan进行授权。我如何使用Grape :: API模块中的authorize!
方法?现在,当我尝试使用它时,它会返回给我:
undefined method 'authorize!' for #<Grape::Endpoint:0xca39664>
答案 0 :(得分:7)
好的,authorize!
是[{1}}的补充,请参阅this source
你可以定义自己的Grape助手:
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
(顺便说一句,我觉得这不是一个好主意)