我的 Model 有三层,从上到下是 Place,Guide,Story
class Place < ActiveRecord::Base
has_many :guides, :dependent => :destroy
def as_json(options={})
options[:except] ||= [:created_at, :updated_at]
options[:include] ||= [:guides]
super(options)
end
end
class Guide < ActiveRecord::Base
belongs_to :place
has_many :stories, :dependent => :destroy
def as_json(options={})
options[:except] ||= [:created_at, :updated_at]
options[:include] ||= [:stories]
super(options)
end
end
如果 render :json => @places 的话,只有第一层,即 Place.as_json 生效,Guide.as_json 根本不会被调用。 这咋办啊,知道请指点,谢了先!