Skip to content

Instantly share code, notes, and snippets.

@allthetime
Created September 27, 2014 04:49
Show Gist options
  • Save allthetime/292427cc0d9799cc9cf7 to your computer and use it in GitHub Desktop.
Save allthetime/292427cc0d9799cc9cf7 to your computer and use it in GitHub Desktop.
RATY STARTER KIT
<form action="/" method="post">
<!-- the stars are here in an empty div -->
<div id="rate" name="raty"></div><br>
<!-- this is the hidden input that raty sends the data to -->
<input type="number" name="rating" style="display:none;" id="rating">
<input type="submit">
</form>
<!-- do this for static ratings -->
<div class="rating" data-score="<%= review.rating %>"></div>
<script src="../javascript/application.js"></script>
<script>
//FOR THE FORM SELECTABLE STARS
$('#rate').raty({
click: function(score, evt) {
$('#rating').val(score)
}});
//FOR THE STATIC STARS
$.each($('.rating'), function( index, object ) {
$(object).raty({
readOnly: true,
number: 5,
// grabs the 'data-score' for div class="rating" and sets the number of stars
score: $(object).attr('data-score')
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment