Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raty stars not showing in RoR application #222

Open
knzudgt opened this issue May 28, 2019 · 1 comment
Open

raty stars not showing in RoR application #222

knzudgt opened this issue May 28, 2019 · 1 comment

Comments

@knzudgt
Copy link

knzudgt commented May 28, 2019

I am trying to use raty in my Ruby on Rails 5.1.6 application.
I downloaded raty from jqueryscript.net then 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 %>

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 would appreciate any help.

@nikfor
Copy link

nikfor commented May 31, 2019

It works for me(for rails 4), may be you need to see in chrome dev tools img src, after this check your public asset dir on availability stars files
`
$(document).ready(function () {
stars_activate = function() {
var stars_options = {
starOff: '/assets/star-off.png',
starOn: '/assets/star-on.png',
starHalf: '/assets/star-half.png',
half: true,
hints: ['very bad', 'bad', 'ok', 'good', 'very good'],
noRatedMsg: 'Нет отзывов',
readOnly: true
}

$('div.rate_star_price_quality').raty(stars_options);
$('div.rate_star_deadline_factor').raty(stars_options);

}

stars_activate();
});
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants