我正在使用RocketPants製作的Rails API。對於JSON序列化,我使用active_model_serializers,對於OAuth - Doorkeeper。在Active_model_serializers中訪問doorkeeper_token(或current_user)
問題在於訪問current_user
助手方法class UserSerializer < ActiveModel::Serializer
。錯誤:
NameError (undefined local variable or method `request' for #<UserSerializer:0xb5892118>)
current_user
幫手使用這個片斷:
User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
和doorkeeper_token
是:
def doorkeeper_token
methods = Doorkeeper.configuration.access_token_methods
@token ||= OAuth::Token.authenticate request, *methods
end
所以當我發現,存在Serializer
訪問的無request
對象。我如何使它可以訪問?或者應該有其他方式來實施current_user
?
在此先感謝
有這個開放的問題:https://github.com/Sutto/rocket_pants/issues/102 –