我是新手到Rails和我使用星级jQuery插件RATY做一些审查/评价的东西。现在我有需要检讨是数据的列表,然后方式审查会在一个自举模式对话框,因为它下面的图片。
一切工作正常,但后来当我点击提交按钮(显示保存更改)中的图片,我没有收到评级的参数,我收到的参数显示,如下图所示。
预期的结果将是包括额定值为好。我跟着步骤添加在application.js中的jquery.raty,并分配在供应商/资产/ JavaScript的文件。此外,我已经在我的文件中添加这段JavaScript代码。
<script>
$('#star-rating').raty({
path: '/assets',
scoreName: 'review[rating]'
});
</script>
一切工作正常,但只是没有经过评级的价值。我检查了结果,该值实际上是保存在hidden_tag,其中包括在jQuery插件,但它只是不流通时,我提交表单。
这是我的表和模式对话框代码
<% @appointment.approve_applicants.each_with_index do |applicant, index| %>
<tr>
<td><%= index + 1 %></td>
<td><%= link_to applicant.user.fullname, applicant.user %></td>
<td><%= link_to "Reviews", applicant.build_review, "data-toggle" => "modal", "data-target" => "#detail#{applicant.id}" %></td>
<td></td>
<!--Modal-->
<div class="modal fade" id="detail<%= applicant.id %>" role="dialog">
<div class="modal-dialog">
<!--Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close close_book_detail" data-dismiss="modal">×</button>
<%= form_for(Review.new) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="form-group row">
<%= f.label :rating, class: 'col-sm-2 form-control-label' %>
<div class="col-sm-6" id='star-rating'>
</div>
</div>
<%= f.label :comment %>
<%= f.text_area :comment, placeholder: "Please enter comment here." %>
<%= f.submit "Save changes", class: "btn btn-primary" %>
<% end %>
</div>
</div>
</div>
</div>
</tr>
<% end %>
以下是该模式对话框的HTML。
<div class="modal fade" id="detail4" role="dialog">
<div class="modal-dialog">
<!--Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close close_book_detail" data-dismiss="modal">×</button>
<form class="new_review" id="new_review" action="/reviews" accept-charset="UTF-8" method=post></form>
<div class="form-group row">
<label class="col-sm-2 form-control-label" for="review_rating">Rating</label>
<div class="col-sm-6" id="star-rating" style="cursor: pointer;">
<img alt="1" src="/assets/star-on.png" title="bad">
<img alt="2" src="/assets/star-on.png" title="poor">
<img alt="3" src="/assets/star-on.png" title="regular">
<img alt="4" src="/assets/star-off.png" title="good">
<img alt="5" src="/assets/star-off.png" title="gorgeous">
<input name="review[rating]" type="hidden" value="3">
</div>
<label for="review_comment">Comment</label>
<textarea placeholder="Please enter comment here." name="review[comment" id="review_comment></textarea>
<input type="submit" name=commit" value="Save changs" class="tbn btn-primary" data-disable-with="Save changes">
</div>
</div>
</div>
</div>
请问有什么解决办法来解决呢?先感谢您。
通过target
选项raty()
获得星级评价为值: -
<script>
$('#star-rating').raty({
path: '/assets',
target : '#id_of_field_to_pass_star_rating',
targetType : 'score',
targetKeep : true
});
</script>
在模式创建一个隐藏字段: -
<div class="col-sm-6" id='star-rating'>
<%=hidden_field_tag "review[rating]", '', id: "id_of_field_to_pass_star_rating" %>
你可以得到各种选项jquery-raty也宝石宝石jquery-raty-rails