# Acts\_as\_rated error

**URL:** <https://www.ruby-forum.com/t/acts-as-rated-error/122383>\
**Category:** Rails\
**Created:** [December 7, 2007, 5:35am UTC](https://www.ruby-forum.com/t/acts-as-rated-error/122383 "2007-12-07T05:35:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubynuby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@rubynuby](https://www.ruby-forum.com/u/rubynuby)\
**Post date:** [December 7, 2007, 5:35am UTC](https://www.ruby-forum.com/t/acts-as-rated-error/122383/1 "2007-12-07T05:35:17Z")

</div>

I’m trying to use acts\_as\_rated and getting this error:

Mysql::Error: #42S22Unknown column ‘ratings.post\_id’ in ‘where  
clause’: SELECT \* FROM ratings WHERE (ratings.post\_id = 14 AND  
(rater\_id = 2)) LIMIT 1

not sure why it’s looking for a post\_id column. shouldn’t it be  
looking for rated\_id ?

here’s my model being rated

class Post \< ActiveRecord::Base  
acts\_as\_rated :rater\_class =\> ‘Inker’, :rating\_range =\> 0…5  
has\_many :ratings  
has\_one :rating\_statistic  
…

“Inker” is my “User” model

I think I did the migration correctly b/c my schema has the necessary  
tables and columns

create\_table “posts”, :force =\> true do |t|  
…  
t.column “rating\_count”, :integer  
t.column “rating\_total”, :integer, :limit =\> 10, :precision  
=\> 10, :scale =\> 0  
t.column “rating\_avg”, :decimal, :precision  
=\> 10, :scale =\> 2  
end

create\_table “rating\_statistics”, :force =\> true do |t|  
t.column “rated\_id”, :integer  
t.column “rated\_type”, :string  
t.column “rating\_count”, :integer  
t.column “rating\_total”, :integer, :limit =\> 10, :precision =\>  
10, :scale =\> 0  
t.column “rating\_avg”, :decimal, :precision =\>  
10, :scale =\> 2  
end

add\_index “rating\_statistics”, [“rated\_type”, “rated\_id”], :name =\>  
“index\_rating\_statistics\_on\_rated\_type\_and\_rated\_id”

create\_table “ratings”, :force =\> true do |t|  
t.column “rater\_id”, :integer  
t.column “rated\_id”, :integer  
t.column “rated\_type”, :string  
t.column “rating”, :integer, :limit =\> 10, :precision =\>  
10, :scale =\> 0  
end

add\_index “ratings”, [“rater\_id”], :name =\>  
“index\_ratings\_on\_rater\_id”  
add\_index “ratings”, [“rated\_type”, “rated\_id”], :name =\>  
“index\_ratings\_on\_rated\_type\_and\_rated\_id”

any help is appreciated

---

<div class="post-metadata">

**Author:** ![rubynuby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@rubynuby](https://www.ruby-forum.com/u/rubynuby)\
**Post date:** [December 8, 2007, 5:01pm UTC](https://www.ruby-forum.com/t/acts-as-rated-error/122383/2 "2007-12-08T17:01:50Z")

</div>

I figured out the problem, It’s this:

> class Post \< ActiveRecord::Base  
> acts\_as\_rated:rater\_class =\> ‘Inker’, :rating\_range =\> 0…5  
> has\_many :ratings  
> has\_one :rating\_statistic

I got confused by the doc. I’m not supposed to add the associations,  
the plugin does it for me (and does it correctly).

I found a curious problem and I don’t know if it’s a problem with the  
plugin or I’m doing something wrong, but all my rating avg are rounded  
to nearest integer. I changed the rating\_total from decimal(10,0) to  
decimal(10,1). Although it’s always going to be .0 (I don’t allow  
fractional ratings), this makes the avg calculation correct. I’m  
using mysql.
