【发布时间】:2011-09-19 12:04:52
【问题描述】:
:reject_if 有一些问题。我不知道为什么下面的代码不起作用。
查看 - _form.html.erb:
<%= f.fields_for :questions do |builder| %>
<div class="nested-field">
<%= builder.label :id, "Question" %><br />
<%= builder.collection_select(:id, Question.all(:order => 'question'), :id, :question, { :prompt => 'Select Question' } ) %>
</div>
<div class="nested-field">
<%= builder.label :test1 %><br />
<%= builder.text_field :test1 %>
</div>
<div class="nested-field">
<%= builder.label :test2 %><br />
<%= builder.text_field :test2 %>
</div>
<div class="nested-field">
<%= builder.label :description %><br />
<%= builder.text_field :description %>
</div>
<br /><br /><br />
<hr />
<% end %>
模型 - questionary.rb:
has_many :questions, :dependent => :destroy
accepts_nested_attributes_for :questions, :reject_if => lambda { |a| a[:id].blank? }, :allow_destroy => true
非常感谢!
【问题讨论】:
标签: ruby-on-rails-3 model nested-forms