这里是上下文:我有一个模型和一个控制器,像这样的(非常简单,它只是一个例子):覆盖JSON哈希
class Model < ActiveRecord::Base
def to_json(options = {})
return super({ :except => [ :id ] })
end
end
class ModelsController < ApplicationController
def show
return @contact.to_json
end
def some_action
return { "foo" => @contact }.to_json
end
end
当我打电话show
动作,Model
的to_json
行动是所谓的,我有没有id
一个JSON:
{"first_name":"Vincent",[...]}
当我打电话some_action
行动,结果是这样的:
{"foo": "<Model:0x000000048c7388>"}
怎么会有这种反应?
{"foo": {"first_name":"Vincent",[...]}}