2011-07-08 83 views
1

我有兩個表格: 報價和零件。我正在使用rails 3.1 ruby​​ 1.9.2。我的代碼如下:RailsCast 197:嵌套窗體未知屬性

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

你摸不着頭腦? – Msencenb

回答

1

運行此遷移

rails g migration AddIdToPart quote_id:integer 
    rake db:migrate 
+0

這個工程。謝謝 – Skilatte