1
我有「時間表」和「時間表」之間的「accep_nested_attributes_for」關係。accepted_nested_attributes_for編輯/更新,而不是新/創建
tms timesheetlines tms timesheet can't be empty
看來它不知道哪個時間表中新:編輯時(編輯/更新)一個時間表,但增加了新的時間表(新/創建)時,它返回以下錯誤這個偉大的工程時間表屬於。這是時間表的關係:
has_many :tms_timesheetlines, :dependent => :destroy, :order=>"daynr ASC"
accepts_nested_attributes_for :tms_timesheetlines, :reject_if => lambda { |a| a[:daynr].blank? }, :allow_destroy => true
並在「新」行動timesheetlines是構建:
@timesheet = TmsTimesheet.new
month_lines = Time.days_in_month(@current_period.period_nr).to_i
month_lines.times { @timesheet.tms_timesheetlines.build }
任何想法,爲什麼它在編輯時工作沒有任何問題,但沒有創造什麼時候?謝謝!
更新:
兩個保存新的和編輯的時間表作品,當我加入這個隱藏字段時,它是一個新的時間表每個timesheetline:
<%= tl.hidden_field :tms_timesheet_id, :value => timesheet %>
這當是一個編輯:
爲什麼這兩者的區別工作?
我已經用一些有效的方法更新了我的問題,但在我看來仍然很奇怪。 – John 2012-04-12 18:31:37