저는 RoR을 처음 사용하고 있으며, 내 앱에 Raty 플러그인을 표시하는 데 문제가 있습니다. 또한 Raty를 추가 한 이후에 다른 Js 함수가 작동을 멈췄다는 것을 알았 기 때문에 Raty가 충돌한다고 생각합니다.Raty jQuery 플러그인이 작동하지 않습니다. Rails 5
Raty 특파원 파일이 추가되었습니다 jquery.raty.js // jquery.raty.css // 이미지
모든 도움에 감사 할 것입니다, 감사합니다!
/models/product.rb
def average_rating
comments.average(:rating).to_f
end
/assets/javascript/application.js
$(document).on('turbolinks:load', function() {
$(".alert").delay(1500).fadeOut("slow");
});
$(document).on('turbolinks:load', function() {
$(".notice").delay(1500).fadeOut("slow");
});
/assets/javascript/site.js
$(document).on('turbolinks:load', function(){
$('.rating').raty({ path: '/assets', scoreName: 'comment[rating]' });
$('.rated').raty({ path: '/assets',
readOnly: true,
score: function() {
return $(this).attr('data-score');
}
});
});
/views/products/_new_comment.erb
<% if signed_in? %>
<h2>Add a review:</h2>
<%= form_for([@product, @product.comments.build]) do |f| %>
<p>
<%= f.label :body, "Comments" %><br>
<%= f.text_area :body %>
</p>
<p>
<%= f.label :rating, "Rating" %><br>
<div class="rating"></div>
</p>
<br>
<p>
<%= f.submit "Submit" %>
</p>
<% end %>
<% end %>
/views/products/_comments.erb
<div class="product-reviews">
<% @comments.each do |comment| %>
<div class="row">
<hr>
<p><%= comment.user.first_name %> <small><em><%= "#{time_ago_in_words(comment.created_at)} ago" %></em></small></p>
<p><div class="rated" data-score="<%= comment.rating %>"></div></p>
<p><%= comment.body %></p>
</div>
<% end %>
</div>
/views/products/show.html.erb
<div class="col-md-12">
<%= render partial:'new_comment' %>
</div>
<div class="col-md-12">
<%= render partial:'comments' %>
</div>