【发布时间】:2016-09-14 10:16:56
【问题描述】:
我的问题是我不明白如何为没有模型的资源设置能力。从现在开始我有一个 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 资源)而且我有一个 cancan 能力
can :me, User, id: user.id
can **index????**, User, id: user.id
为自定义 me 操作设置一个功能并不难,但是如何在 Profiles 控制器中为 :index 设置它(因为我已经为 UsersController 设置了功能,它也有:index 操作,我不想更改它们)
我只是一个初学者,所以如果我的解释不是那么直截了当(如果需要,我可以写一些额外的解释)和我的英语,请原谅我
【问题讨论】:
标签: ruby-on-rails api cancancan