Hey guys,
I’m not that great with Rails yet, but I’m trying to get there.
I’m developing a site where users will be able to upload pictures and
videos (eventually). I want to set the pictures and the videos up as
separate models, or at least so they will act like it. Comments, tags,
and ratings will go onto the pictures and videos. I’ve decided the
easiest way to do it, while keeping everything nice and DRY, is to
create a “content_item” model, through which the pictures and videos
will act.
I’m trying to find a way to basically do the following:
Picture.find(1) will go find the item with id = 1 in the content_items
model. If the content_type at id 1 isn’t a picture, it will return an
error.
Video.find_by_username(“Foobar”) would return all videos for the user
Foobar by using content_type “Video”
I don’t think polymorphic associations applies to this, since the
content doesn’t has_one video, the content IS the video, if that makes
any sense.
As of right now, I have a blank model. I know the answer is something
simple, but I just can’t seem to find it.
Thanks,
Jonathon