Reputation: 221
I am using jquery raty to implement star rating and score display for my ruby on rails site. i can use the plugin to accept votes however i am stuck to display the scores after they are retrieved from the DB. Say i need to show a vote from the DB, the voting user and the score are stored in a variable say @user.score (e.g. @user.score = 3).
$('#star').raty({
readOnly: true,
start: 3
});<div><div id="star"></div>
OR
$('#start').raty({ start: function() { return $(this).attr('data-rating'); } }); <div id="star" data-rating="3"></div>
But now the score value 3 is stored in @user.score (a variable). How can I pass the score value to the star display?
Public function $('#star').raty('score'); looks like it is doing something to the score but I don't understand what it is doing. Can tell me?
Maybe I am in a wrong direction to display the retrieved score. Please tell me.
Please help Thanks batterhead
Upvotes: 1
Views: 2927
Reputation: 976
The correct answer would appear to be:
$('#star').raty({ score: 2 });
so, you can do
$('#star').raty({ score: myScore });
Upvotes: 1
Reputation: 707696
Here's the doc page for the .raty()
plugin. It looks to me like there are several examples for how to initialize a given set of ratings with it's initial value. Here's one of those examples:
$('#star').raty({
start: 2
});
<div id="star"></div>
If you have the score in a variable named myScore
, you can do this:
$('#star').raty({
start: myScore
});
Upvotes: 0