Acts_as_rateable plugin help!

Hello,
I am having some trouble figuring out how to use the rateable plugin. i
followed as close as the directions located at
http://www.naffis.com/blog/articles/2006/08/31/rails-ajax-star-rating-system
but i fail at working it.

i am getting this error

You have a nil object when you didn’t expect it!
The error occured while evaluating nil.rating
Extracted source (around line #1):

1: <%= number_with_precision(asset.rating, 1) %>/5 Stars

2:


    3:

  • 4: Currently <%= number_with_precision(asset.rating, 1) %>/5
    Stars.

    the model i am trying to use rateable with is my address model (my
    addresses table that contains name, zipcode, etc…)

    if my view is this:

    <% for column in Address.content_columns %>

    <%= column.human_name %>: <%=h @address.send(column.name) %>

    <% end %>

    where do i add this?

    <%= render :partial => "rating/rating", :locals => { :asset => @asset } %>

    how does the rating system know to keep values for my address? dont i
    need to make some sort of relationship?

    thanks for any help!!!

Dear Koloa:

I went through the walkthrough you linked to, and got past the issue you
encountered…

The error you are seeing has to do with the the fact that the partial is
referring to asset. You probably want to change that to something else
(as well as in the RJS code and the controller).

You also want to be careful with the line:

Rating.delete_all([“rateable_type = ‘Posting’ AND rateable_id = ? AND
user_id = ?”, @posting.id, current_user_id.to_s])

current_user_id is a string in the migration described

If you (or anyone else) wants to see the code I came up with, please
email me… I wrote a very simple app that lets you create postings
using scaffolding, and vote on them… The only thing that I’m not happy
with is that after voting, the post name disappears! (and I am pretty
sure that has to do with the fact that the rate controller needs to do
something else that I’m not doing, but I’m not 100% sure…

[‘dominique’, ‘[email protected]’, ‘com’].join(’.’)

Thanks!
Dominique

koloa wrote:

Hello,
I am having some trouble figuring out how to use the rateable plugin. i
followed as close as the directions located at
http://www.naffis.com/blog/articles/2006/08/31/rails-ajax-star-rating-system
but i fail at working it.

i am getting this error

You have a nil object when you didn’t expect it!
The error occured while evaluating nil.rating
Extracted source (around line #1):

1: <%= number_with_precision(asset.rating, 1) %>/5 Stars

2:


    3:

  • 4: Currently <%= number_with_precision(asset.rating, 1) %>/5
    Stars.

    the model i am trying to use rateable with is my address model (my
    addresses table that contains name, zipcode, etc…)

    if my view is this:

    <% for column in Address.content_columns %>

    <%= column.human_name %>: <%=h @address.send(column.name) %>

    <% end %>

    where do i add this?

    <%= render :partial => "rating/rating", :locals => { :asset => @asset } %>

    how does the rating system know to keep values for my address? dont i
    need to make some sort of relationship?

    thanks for any help!!!

Hello Dominique,
Thanks for the reply. I seemed of gotten passed that problem but now i
have a new one!

when i click on the stars, no action seems to take place. i put printout
statements to see if there is any action but nothing.

is asset the model that is acting as rateable? if my model is address,
do i set asset => @address in my view?

also, do i move the rate function in the ratingController to my personal
controller?

Thanks

im almost there.

it seems everything is fine but how do i make it so after the user
rates, it takes away there ability to change the rating? i want to
display something like, :sorry you rated already etc…"

but what i did is changed current_user.id to the params[:id] (which is
my address ID)

is this correct?

use the rated_by_user method

@rate.rated_by_user?(@session[:user]) and user?

On 9/24/06, koloa [email protected] wrote:

my address ID)

is this correct?


Posted via http://www.ruby-forum.com/.

www.blogsaic.com
search, post, blog

It looks like your steaming along again!!!

Post again if you feel any of your questions have not been answered :slight_smile:

Thanks!
Dominique

koloa wrote:

im almost there.

it seems everything is fine but how do i make it so after the user
rates, it takes away there ability to change the rating? i want to
display something like, :sorry you rated already etc…"

but what i did is changed current_user.id to the params[:id] (which is
my address ID)

is this correct?

hello,

how do i use this? do all sessions have user or do i have to define it
in a session model?

do i put this code in the rate function and if its true, return and do
nothing? else, record the rating?

thanks Dominique
i still have a few questions about the plugin…

what is rateable_id and user_id in the rateable table? in my rate
function, rateable_type = my model name, rateable_id = my model id, and
user_id = also my model id.

//my model == Address table.

is this right?

Dion H. wrote:

use the rated_by_user method

@rate.rated_by_user?(@session[:user]) and user?

On 9/24/06, koloa [email protected] wrote:

my address ID)

is this correct?


Posted via http://www.ruby-forum.com/.

www.blogsaic.com
search, post, blog

hello dion, your help would be greatly appeciated if you can share your
code.

my email is rubytree at-verizon-dot-net

THANKS!

Dion H. wrote:

rateable_id is the id of the table you are rating

so for you, rateable_id will be equal to address_id

user_id should be the id of the user who posts the rate, this is used to
ensure that a user only rates something once.

there is an example of my rating system at www.blogsaic.com

it works pretty much like the rating system at youtube

login and rate some tiles

if you want a similar system, I can give you all the bits of code you
need

On 9/24/06, koloa [email protected] wrote:

is this right?

www.blogsaic.com
search, post, blog

rateable_id is the id of the table you are rating

so for you, rateable_id will be equal to address_id

user_id should be the id of the user who posts the rate, this is used to
ensure that a user only rates something once.

there is an example of my rating system at www.blogsaic.com

it works pretty much like the rating system at youtube

login and rate some tiles

if you want a similar system, I can give you all the bits of code you
need

On 9/24/06, koloa [email protected] wrote:

is this right?

www.blogsaic.com
search, post, blog

Hi Dominique,
I read your post and was hoping that you could share your rating
system code or tips.
I am putting up a college survey site and need users to rate the
surveys.
I am looking at implementing rating display, number of votes, etc.

Also, i see that you have “listing with number of views” as well on
your site.
Could you please let me know how you implmented it?

Thanks in advance!
Cheers!
Vish

On Sep 23 2006, 12:19 pm, Dominique P. <rails-mailing-l…@andreas-

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs