I would like to use raty for rating the users of my Rails 5.1.6 application and found Elizabeth Le's documentation on Raty and Ruby on Rails. As suggested in that documentation, I went to the GitHub raty's page and I copied star-half.png, star-off.png and star-on.png in app/assets/images and jquery.raty.js in app/assets/javascripts. Then I added the following code in /app/views/users/show.html.erb:
<% if !Review.exists?(reviewer_id: current_user.id, reviewed_id: @user.id) && current_user != @user %>
<h2> Rate this user </h2>
<%= form_for(current_user.active_reviews.build) do |f| %>
<div><%= f.hidden_field :reviewed_id, value: @user.id %></div>
<div id=“rating-form”>
<label> Rating </label>
</div>
<%= f.submit "Submit your rating", class: "btn btn-primary" %>
<% end %>
<% end %>
Review is an association between a user and another user, having reviewer_id, reviewed_id and rating as attributes.
In app/assets/javascrits/custom.js I added instead the following javascript code:
$(document).on('turbolinks:load', function() {
$("#rating-form").raty({
path: "/assets/",
scoreName: "review[rating]"
});
});
The stars however do not show up.
I tried to use as path path: "/assets/images" and to add //= require jquery.raty to application.js with no results. I even tried to add the jquery code in view, included in a <script> tag at the very bottom of the page, but nothing changed.
I also tried to download the images and the jquery.raty.js file from jqueryscript.net, but this did not change the result.