relationships in Rails

I understand basic relationships in rails, but I'm confused on how to
solve a particular problem.

I have posts and products. Both of which should be able to have
multiple photos uploaded to them. So, posts have many photos and photos
belongs to posts - BUT products have many photos too and photos belongs
to products.

Products and posts have no relationship but they share the same child.

Is there a clean (non-hack) sort of way to solve this in Rails without
creating a bunch of extra classes.