Understanding Polymorphicness

Rating Model - belongs_to :ratable, :polymorphic => true
User Model & Comment Model & Picture Model - has_one :rating, :as
=> :ratable

Okay, so now my "Ratings" table should have these columns:
ups = 5
downs = 2
ratable_id = 3
ratable_type = "user"

And that will automatically make user # 3 have user.rating.ups = 5
right? And the ratable_type will always use the singlular form, right?

Anyone know if this is the best way to do this?

And that will automatically make user # 3 have user.rating.ups = 5

Yes

right? And the ratable_type will always use the singlular form, right?

Yes

For some reason this isn't working.

I have done all that I stated above, then I made an object Rating with
a ratable_id = 6, ratable_type = "web_page"

But WebPages.find(6).rating returns a Nil. Ideas?

Does there need to be a middle table or something with Polymorphic? I
didn't see any mention of it.

-Ryan

Not sure if this is the problem, but the descrimiator column
(ratable_type in this case) should have a value that matches the camel
cased class name. In your original post it looks like you have a
lowercase 'u' (user) instead of uppercase ("User").

Looking at a later post this appears to be the case. You should have
"WebPage" as the ratable_type, not "web_page".

HTH,
AndyV

PS: Any job posting dissections you want to share :slight_smile: