我正在使用嵌套表单 gem,其中有两个字段, View 给出为
<%= f.fields_for :round_questions do |question| %>
<%= question.label :question %>
<%= question.text_field :question %>
Rate the Answer</br></br>
<div class="star-questions" ></div>
<%= question.text_field :answer_rating, :class=> 'star-answer', :disabled=>true %>
<%= question.link_to_remove "Remove this Question" %>
<% end %>
<%= f.link_to_add "Add a Question", :round_questions,
:class=> 'btn waves-effect waves-light btn-medium custom_btn_gray' %>
在 Controller 中我有
@interview_round = InterviewRound.where(id: params[:id]).first
5.times {@interview_round.round_questions.build}
respond_to do |format|
format.js
end
现在,当表单加载时,将出现 5 个问题,我只想在有人添加问题时才提供删除链接,但此链接提供了所有问题的删除链接, 请告诉我如何解决这个问题?
最佳答案
尝试这样给出
<%= question.link_to_remove "Remove this Question" if question.object.persisted? %>
关于javascript - Rails 4 Nested_form 在 5 个问题后删除链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30865617/