Rails: Create a new entry in a model that belongs_to two other models
问题 Consider a Store that has_many Products which have_many Opinions. Here are Models: Store: class Store < ActiveRecord::Base attr_accessible :desc, :location, :name, :phone, :status, :url has_many :products has_many :opinions, :through => :products end Product: class Product < ActiveRecord::Base attr_accessible :desc, :name, :status, :url belongs_to :store has_many :opinions end finally, Opinion: class Opinion < ActiveRecord::Base attr_accessible :content, :eval, :status belongs_to :store