Ruby on rails 3 中的许多模型记录具有多个关系列

Ruby on rails 3 中的许多模型记录具有多个关系列,ruby-on-rails-3,has-many,belongs-to,Ruby On Rails 3,Has Many,Belongs To,我有品牌型号和价格型号,因此: brand.rb class Brand < ActiveRecord::Base attr_accessible :name, :a4_single, :a4_double, :a3_double, :two_a3_double has_many :prices, :dependent => :destroy end class Price < Brand attr_accessible :type, :quantity, :pr

我有
品牌
型号和
价格
型号,因此:

brand.rb

class Brand < ActiveRecord::Base
  attr_accessible :name, :a4_single, :a4_double, :a3_double, :two_a3_double
  has_many :prices, :dependent => :destroy
end
class Price < Brand
  attr_accessible :type, :quantity, :price, :brand_id
  belongs_to :brand
end
class品牌:破坏
结束
price.rb

class Brand < ActiveRecord::Base
  attr_accessible :name, :a4_single, :a4_double, :a3_double, :two_a3_double
  has_many :prices, :dependent => :destroy
end
class Price < Brand
  attr_accessible :type, :quantity, :price, :brand_id
  belongs_to :brand
end
等级价格
我希望能够在每个产品列中插入多条
记录,即
:a4\u single
中插入10条
价格
记录,八条
:a4\u double
中插入两条
:a3\u double
中插入两条,八条
中插入两条a3\u double


我只是猜测上面定义的
关系有很多是正确的,我真的不知道如何从这里开始。

你不应该再继续下去了

做这样的事

class Brand < ActiveRecord::Base
  has_many :brand_prices
  has_many :prices, :through => :brand_prices
  attr_accessible :name
end

class Price < ActiveRecord::Base
  has_many :brand_prices
  has_many :brands, :through => :brand_prices
  attr_accessible :price, :quantity, :type
end

class BrandPrice < ActiveRecord::Base
  belongs_to :brand
  belongs_to :price
end
class品牌:品牌价格
可访问属性:名称
结束
类价格:品牌\u价格
可访问属性:价格、数量、类型
结束
类BrandPrice
这个解决方案是有道理的,但它让我想知道一些事情:我已经嵌套了表单/模型,并通过它们之间的关系设置了一个
有很多。首先,我如何将
Price
实例与特定的
Brand
列相关联?我想做一个
品牌。列名。每一个
系列都选择
的东西,但这似乎是毫无根据的。其次,保存定价信息是可行的,但是
编辑
屏幕显示没有值,尽管它们存储在数据库中。有什么想法吗?我一直在想这个问题,但你肯定帮我找到了解决办法。我在另一款车型中将
品牌
栏信息翻了一番。危机结束了。谢谢你。