所以我正在尝试使用rails 4和ruby 2.0.0 ActiveModelSerializer gem(0.8.1)和Doorkeeper gem(实际上是fork(https://github.com/simonbnrd/doorkeeper)来构建rails API应用程序使用这个游戏mongoid 4,但我不认为是这样)。当我启动我的应用程序并使用 ActiveModel::ArraySerializer 创建新对象然后尝试将其呈现为 json - 一切正常。但是,如果我在调用方法(来自 Doorkeeper gem)之后执行相同的操作序列,Doorkeeper::TokensController.create 渲染到 json 应用程序突然返回字符串。试图调查这个问题我找不到 to_json 方法的源代码位置。
def index
@users = User.all
a = ActiveModel::ArraySerializer.new(@users)
raise a.class.method(:to_json).source_location.inspect
render json: @users
end
这返回
gems/activesupport-4.0.1/lib/active_support/core_ext/object/to_json.rb
在门卫打电话之前
nil
后