1

I'm using the jquery raty star rating system and it worked. Except that when I edit a review for example that has 4 stars, the edit page shows 0 stars. Should this how the jquery raty behaves?

Or is there a way that when I edit that review, the edit page will still retain the 4 stars but still can edit?

This is my code for edit page:

<%= simple_form_for([@book, @review]) do |f| %>
    <div id="rating-form">
        <label>Rating</label>
    </div>
    <%= f.input :comment %>
    <%= f.button :submit %>
<% end %>


<script>
    $('#rating-form').raty({
        path: '/assets/',
        scoreName: 'review[rating]'
    });
</script>
Jeramae Bohol
  • 185
  • 2
  • 14

2 Answers2

1

You just have to add an option. Try this:

 $('#div-rating').raty({
    path: '/assets/',
    scoreName: 'review[rating]',
    score: @review.rating
 });

You can read the documentation here to know the list of options: https://github.com/wbotelhos/raty#options

Terry Raimondo
  • 629
  • 7
  • 25
1

you need to enter the following- score: <%= @review.rating %>. It worked for me. :)

<script>
    $('#rating-form').raty({
        path: '/assets/',
        scoreName: 'review[rating]',
        score: <%= @review.rating %>
    });
</script>
F A
  • 326
  • 2
  • 12