私はネストされたフォームを持っており、フィールドでレイティスターを使用しているライアンベイツによるnested_form gemを使用すると、フォームは次のように与えられます
<%= 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は次のように与えられます
$(document).ready(function() {
$('.star-questions').raty({
targetType : 'score',
targetKeep : true
});
$(document).on('click', '#add-fields', function(){
$('.star-questions').raty({
targetType : 'score',
targetKeep : true
});
});
問題は、[質問の追加] をクリックすると、以前の星の評価が空になることです。すべての星の質問に率関数を再度渡しているため、これが発生する理由はわかっています。以前の星の評価を維持したまま質問を追加する方法を教えてください。