我正在尝试使用jquery raty在我的应用程序中添加星级评论,但我无论如何也想不出为什么我的餐厅评论页面上看不到星级。我还把明星的照片上传到了AWS
我下载了文件jquery.raty.js并将其放入我的app/assets/javascripts文件夹中。这是我的show.html.erb文件:
<div class="row">
<div class="col-3">
<%= image_tag @restaurant.image_url %>
<h2>
<%= @restaurant.name %>
</h2>
<p>
<strong>Address:</strong>
<%= @restaurant.address %>
</p>
<p>
<strong>Phone:</strong>
<%= @restaurant.phone %>
</p>
<p>
<strong>Website:</strong>
<%= link_to @restaurant.website, @restaurant.website %>
</p>
<%= link_to "Write Review", new_restaurant_review_path(@restaurant), class: "btn btn-primary" %>
</div>
<div class="col-9">
<% if @reviews.blank? %>
<h3>No Reviews yet. Be the first to write one!</h3>
<% else %>
<% @reviews.each do |review| %>
<div class="star-rating" data-score= <%= review.rating %> ></div>
<p><%= review.rating %></p>
<p><%= review.comment %></p>
<% end %>
<% end %>
</div>
</div>
<%= link_to 'Edit', edit_restaurant_path(@restaurant), class: "btn btn-link" %> |
<%= link_to 'Back', restaurants_path, class: "btn btn-link" %>
<script>
$('.star-rating').raty({
path: 'https://pbukurasyelpdemo.s3.us-east-2.amazonaws.com/uploads/stars', readOnly: true, score: function() {
return $(this).attr('data-score');
}
});
</script>application.js
//= require jquery
//= require rails-ujs
//= require jquery.raty
//= require turbolinks
//= require_tree .这是我的视图/布局/_bootstrap.html.erb
<link href="//stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script
href="//code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>任何帮助都将不胜感激!
发布于 2020-03-17 18:44:11
您似乎加载了两次jquery,一次是在application.js中,另一次是通过cdn。
您是否在控制台中看到任何错误?
https://stackoverflow.com/questions/60688959
复制相似问题