1
我正在rails 3中構建一個多嵌套的表單。我使用formtastic_cocoon gem,但我不認爲這對這個問題有很大的影響。深嵌套表格數據沒有進入數據庫,沒有錯誤
我有用戶,用戶有任務,任務有步驟。 嵌套是用戶>任務>步驟。 我可以動態添加和刪除任務字段給用戶,以及任務中的步驟字段。
但是,當我提交表單時,用戶獲取任務,但任務>步驟不會保存到數據庫。
Rails沒有返回任何錯誤,只是沒有任何反應。
我的模型
Class User < ActiveRecord::Base acts_as_authentic has_many :tasks accepts_nested_attributes_for :tasks, :reject_if=> proc {|attributes| attributes[:entry].blank?}, :allow_destroy => true end Class Task < ActiveRecord::Base attr_accessible :entry belongs_to :user has_many :steps accepts_nested_attributes_for :steps, :reject_if=> proc {|attributes| attributes[:title].blank?}, :allow_destroy => true end Class Step < ActiveRecord::Base attr_accesible :title belongs_to :task end
在我form.html.erb我有
<%= semantic_form_for @user %> <%= form.inputs :username, :password %> <div> <% form.semantic_form_fields_for :tasks do |builder| %> <%= render 'task_fields', :f=>builder %> <% end %> <%= link_to_add_association 'add task', form, :tasks %> </div>
的_task_fields.html.erb看起來像這樣
<div class="nested-fields"> <%= link_to_remove_association "remove task", f %> <%= f.inputs :entry %> <div> <% f.semantic_form_fields_form :steps do |builder| %> <%= render 'step_fields' :f => builder %> <% end %> <%= link_to_add_association 'add step', f, :steps %> </div> </div>
最後,_step_fields .html.erb頁面是
<div class="nested-fields"> <%= link_to_remove_association "remove step", f %> <%= f.inputs :title %> </div>
我沒有看到任何「警告:」或任何錯誤信息。我在哪裏可以找到? 你說的沒錯,解決了這個問題。謝謝! – pedalpete 2011-02-10 02:34:57