我有两个型号:(相册和产品)
1)内部模型
内部album.rb:
class Album < ActiveRecord::Base
attr_accessible :name
has_many :products
end
内部product.rb:
class Product < ActiveRecord::Base
attr_accessible :img, :name, :price, :quantity
belongs_to :album
end
2)使用“ 轨道控制台 ”,哪能设定关联(所以可以用“<%= Product.first.album.name%>”)?
如
a = Album.create( :name => "My Album" )
p = Product.create( :name => "Shampoo X" )
# what's next? how can i set the album and the product together?