# Rateable plugin problem

**URL:** <https://www.ruby-forum.com/t/rateable-plugin-problem/141912>\
**Category:** Rails\
**Created:** [July 1, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/rateable-plugin-problem/141912 "2008-07-01T18:20:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nishi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@nishi](https://www.ruby-forum.com/u/nishi)\
**Post date:** [July 1, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/rateable-plugin-problem/141912/1 "2008-07-01T18:20:14Z")

</div>

I am having some problem 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](http://www.naffis.com/blog/articles/2006/08/31/rails-ajax-star-rating-system)  
but there seem to be some problem.

I am getting the following 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(picture.rating, 1) %\>/5 Stars  
  
2:

  
3: -   
4: Currently \<%= number\_with\_precision(picture.rating, 1) %\>/5  
Stars.

what exactly this picture is associated with? Is this picture, in my  
view corresponds to :picture following in rjs file?

page.replace\_html â€œstar-ratings-blockâ€, :partial =\> â€˜rating/ratingâ€™,  
:locals =\> { :picture=\> @picture }

## Code at controller looks like:

def rate  
@picture = Picture.find(params[:id])  
Rating.delete\_all([“rateable\_type = ‘Picture’ AND rateable\_id = ? AND  
user\_id = ?”,  
@picture.id, current\_user.id])  
@picture.add\_rating Rating.new(:rating =\> params[:rating],  
:user\_id =\> current\_user.id)  
end  
end

Any help would be appreciated. thanks.

---

<div class="post-metadata">

**Author:** ![nishi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@nishi](https://www.ruby-forum.com/u/nishi)\
**Post date:** [July 1, 2008, 6:24pm UTC](https://www.ruby-forum.com/t/rateable-plugin-problem/141912/2 "2008-07-01T18:24:44Z")

</div>

\<%= number\_with\_precision(picture.rating, 1) %\>

picture should be @picture

---

<div class="post-metadata">

**Author:** ![nishi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@nishi](https://www.ruby-forum.com/u/nishi)\
**Post date:** [July 2, 2008, 2:01am UTC](https://www.ruby-forum.com/t/rateable-plugin-problem/141912/3 "2008-07-02T02:01:25Z")

</div>

Thorsten M. wrote:

> \<%= number\_with\_precision(picture.rating, 1) %\>
> 
> picture should be @picture

I even thought the same thing and tried that one before posting here,  
But no luck still ☹
