0
我想要3种模型:订单,产品,属性。每个订单都可以有很多属性。每个产品都可以有很多属性,当然订单可以有很多产品。这里是我的模型:多对多关系
class Order < ActiveRecord::Base
belongs_to :customer
has_and_belongs_to_many :products
has_and_belongs_to_many :attributes
has_one :invoice_address, class_name: 'OrderAddress'
has_one :delivery_address, class_name: 'OrderAddress'
validates :number, presence: true
validates :total_amount, presence: true
end
product.rb
class Product < ActiveRecord::Base
has_and_belongs_to_many :orders
has_and_belongs_to_many :attributes
end
和attribute.rb
class Attribute < ActiveRecord::Base
has_and_belongs_to_many :orders
has_and_belongs_to_many :products
end
基于我对这个职位http://jonathanhui.com/ruby-rails-3-model-many-many-association的问题我的代码,当我想创造新的订购:
dev_customer = Customer.create(:name => 'dev')
dev_user = dev_customer.users.create(:email => '[email protected]', :password => 'bk020488', :password_confirmation => 'bk020488')
first_order = dev_customer.orders.create(:number => 1, :total_amount => 555, :paid_amount => 555)
first_order.products.create(:name => 'First product', :price => 111, :qty => 1)
first_order.products.create(:name => 'Second product', :price => 222, :qty => 2)
它打破了第5行与消息
未定义的方法'键为#
我该怎么办错了吗?