如何在没有模型 cancancan 的情况下为 api 资源设置能力

how to set an ability for api resource without model cancancan

我的问题是我不明白如何在没有模型的情况下为资源设置能力。从现在开始我只有一个 api 控制器

class Api::V1::ProfilesController < Api::V1::BaseController   

  before_action :doorkeeper_authorize! 

  authorize_resource class: User
  respond_to :json

  api :GET, '/profiles', "This is index for all registered users except current user" 
  def index    
    render json: User.where.not(id: current_resource_owner.id)   
  end 

  api :GET, '/profiles/me', "This is current user profile's data"
  def me    
    render json: current_resource_owner      
  end

  protected
  def current_resource_owner
    @current_resource_owner ||= User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
  end
end

在这种情况下,Profile 不是模型,它只是一个控制器(api 资源)我还有康康舞能力

can :me, User, id: user.id
can **index????**, User, id: user.id

为自定义 me 操作设置能力并不难,但是如何仅在 Profiles 控制器中为 :index 设置能力(因为我已经为UsersController,它也有 :index 操作,我不想更改它们)

我只是一个初学者,所以如果我的解释不是那么直截了当(如果需要我可以写一些额外的解释)和我的英语,请原谅我

请看这个:

查看这一行:authorize_resource :class => false