0

私はこれらのクラスを持っています:

class Product
 attr_accessible :name, ...
 has_many :images
end

class Image
 attr_accessible :image, :position, :product_id, :title
 belongs_to :product
end

アクション:

def list
  render :json => {:Result => "OK", :Records => Product.all}
end

製品のすべての属性を列挙せずに、ネストされた属性としてすべての製品の独自の画像を含めるにはどうすればよいですか?

4

1 に答える 1

0

使用できますto_json(:include => :attr)

def list
  render :json => {:Result => "OK", :Records => Product.all}.to_json(:include => :images)
end
于 2013-03-27T00:11:48.560 に答える