我想在我的 API 中使用 CanCan 进行授权。例如,如何使用authorize!
Grape::API 模块中的方法?现在,当我尝试使用它时,它会返回给我:
undefined method 'authorize!' for #<Grape::Endpoint:0xca39664>
问问题
1903 次
1 回答
7
好的,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
或使用模块助手:(helpers CanCan::ControllerAdditions
顺便说一句,我认为这不是一个好主意)
于 2014-03-03T13:58:16.960 回答