I have two models: (Albums and product)
1) Internal models
Inside album.rb:
class Album < ActiveRecord::Base attr_accessible :name has_many :products end
Inside product.rb:
class Product < ActiveRecord::Base attr_accessible :img, :name, :price, :quantity belongs_to :album end
2) Using the " rails console ", how can I establish associations (so that I can use "<% = Product.first.album.name%>")?
eg.
a = Album.create( :name => "My Album" ) p = Product.create( :name => "Shampoo X" )
rosary dextrose
source share