Take the 2-minute tour ×

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).

  1. What is the syntax to display the stars in the .erb form? I know if the score is a constant, e.g. 3, I can write something like:

readOnly: true,
start: 3

<div><div id="star"></div>


$('#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?

  1. 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?

  2. Maybe I am in a wrong direction to display the retrieved score. Please tell me.

Please help Thanks batterhead

share|improve this question

2 Answers 2

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:

  start: 2

<div id="star"></div>

If you have the score in a variable named myScore, you can do this:

  start: myScore
share|improve this answer
hi jfriend00, thanks for your answer. i know the js part can accept an initial value from a variable like myScore. what i don't know is the .erb form part, i don't know how to write the statement for div tag to supply myScore, e.g. @user.myScore. –  user661684 Jan 20 '12 at 7:00
@user661684 - I would suggest you clarify your question to make it absolutely clear that you're asking what to put in the erb file so the initial rating from the db appears in the page. That was certainly not obvious to me that that was your question. Rails is not my area so you will need someone else to help you with that. –  jfriend00 Jan 20 '12 at 7:26
jfriend00, i mentioned it clearly that "What is the syntax to display the stars in the .erb form?" hope someone else can help showing me how to write the form. thanks anyway. –  user661684 Jan 20 '12 at 7:51

The correct answer would appear to be:

$('#star').raty({ score: 2 });

so, you can do

$('#star').raty({ score: myScore });
share|improve this answer

Your Answer


