您好我在rails4中使用raty星级评分并使用gem 'nested_form'
创建多个星级评分,如下所示
<%= f.fields_for :round_questions do |question| %>
<%= question.label :question %>
<%= question.text_field :question %>
<div class="star-questions" > </div>
<%= question.text_field :answer %>
<% end %>
<%= f.link_to_add "Add a Question", :round_questions,
:class=> 'btn waves-effect waves-light btn-medium custom_btn_gray', :id => "add-fields" %>
并且javascript以
的形式给出$('.star-questions').raty({
target : $("input[id^='interview_round_round_questions_attributes_'][id$=_answer]"),
targetType : 'score',
targetKeep : true
});
浏览器正在获取此HTML
<div class="fields">
<label for="interview_round_round_questions_attributes_0_question" class="">Question</label>
<input type="text" name="interview_round[round_questions_attributes][0][question]" id="interview_round_round_questions_attributes_0_question">
<div class="star-questions" style="cursor: pointer; width: 100px;"><img src="/assets/jquery.raty/star-off.png" alt="1" title="bad"> <img src="/assets/jquery.raty/star-off.png" alt="2" title="poor"> <img src="/assets/jquery.raty/star-off.png" alt="3" title="regular"> <img src="/assets/jquery.raty/star-off.png" alt="4" title="good"> <img src="/assets/jquery.raty/star-off.png" alt="5" title="gorgeous"><input type="hidden" name="score"></div>
<input type="text" name="interview_round[round_questions_attributes][0][answer]" id="interview_round_round_questions_attributes_0_answer">
</div><div class="fields">
<label for="interview_round_round_questions_attributes_1_question">Question</label>
<input type="text" name="interview_round[round_questions_attributes][1][question]" id="interview_round_round_questions_attributes_1_question">
<div class="star-questions" style="cursor: pointer; width: 100px;"><img src="/assets/jquery.raty/star-off.png" alt="1" title="bad"> <img src="/assets/jquery.raty/star-off.png" alt="2" title="poor"> <img src="/assets/jquery.raty/star-off.png" alt="3" title="regular"> <img src="/assets/jquery.raty/star-off.png" alt="4" title="good"> <img src="/assets/jquery.raty/star-off.png" alt="5" title="gorgeous"><input type="hidden" name="score"></div>
<input type="text" name="interview_round[round_questions_attributes][1][answer]" id="interview_round_round_questions_attributes_1_answer">
</div><div class="fields">
<label for="interview_round_round_questions_attributes_2_question">Question</label>
<input type="text" name="interview_round[round_questions_attributes][2][question]" id="interview_round_round_questions_attributes_2_question">
<div class="star-questions" style="cursor: pointer; width: 100px;"><img src="/assets/jquery.raty/star-off.png" alt="1" title="bad"> <img src="/assets/jquery.raty/star-off.png" alt="2" title="poor"> <img src="/assets/jquery.raty/star-off.png" alt="3" title="regular"> <img src="/assets/jquery.raty/star-off.png" alt="4" title="good"> <img src="/assets/jquery.raty/star-off.png" alt="5" title="gorgeous"><input type="hidden" name="score"></div>
<input type="text" name="interview_round[round_questions_attributes][2][answer]" id="interview_round_round_questions_attributes_2_answer">
</div><div class="fields">
<label for="interview_round_round_questions_attributes_3_question">Question</label>
<input type="text" name="interview_round[round_questions_attributes][3][question]" id="interview_round_round_questions_attributes_3_question">
<div class="star-questions" style="cursor: pointer; width: 100px;"><img src="/assets/jquery.raty/star-off.png" alt="1" title="bad"> <img src="/assets/jquery.raty/star-off.png" alt="2" title="poor"> <img src="/assets/jquery.raty/star-off.png" alt="3" title="regular"> <img src="/assets/jquery.raty/star-off.png" alt="4" title="good"> <img src="/assets/jquery.raty/star-off.png" alt="5" title="gorgeous"><input type="hidden" name="score"></div>
<input type="text" name="interview_round[round_questions_attributes][3][answer]" id="interview_round_round_questions_attributes_3_answer">
我正在使用唯一ID,但是当我填写任何一个答案评级时会发生什么,其他一个数字也会显示。请指导我如何解决这个问题。