我有两张桌子: 报价和部分。我正在使用rails 3.1 ruby 1.9.2。我的代码如下:
class Quote < ActiveRecord::Base
attr_accessible :name, :customer_id, :part_id, :date, :quote_id
has_many :customers
has_many :cycles
has_many :parts, #:dependent => :destroy
accepts_nested_attributes_for :parts
end
class Part < ActiveRecord::Base
belongs_to :quote
end
QuotesController
def new
@quote = Quote.new
@customers=Customer.find(:all)
@cycles = Cycle.find(:all)
1.times {@quote.parts.build}
end
_form
<% f.fields_for :parts do |builder| %>
<%= render "cycle_fields", :f => builder%>
当我尝试渲染表单时,我得到一个未知属性:quote_id。
答案 0 :(得分:1)
运行此迁移
rails g migration AddIdToPart quote_id:integer
rake db:migrate