# Polymorphic Associations

**URL:** <https://discuss.rubyonrails.org/t/polymorphic-associations/54648>\
**Category:** rubyonrails-talk\
**Created:** [September 25, 2010, 3:47am UTC](https://discuss.rubyonrails.org/t/polymorphic-associations/54648 "2010-09-25T03:47:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [September 25, 2010, 3:47am UTC](https://discuss.rubyonrails.org/t/polymorphic-associations/54648/1 "2010-09-25T03:47:08Z")

</div>

Hi, I'm following the Polymorphic Associations test， issue as following.

---

<div class="post-metadata">

**Author:** ![AppleII717](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/appleii717/32/3905_2.png) [@AppleII717](https://discuss.rubyonrails.org/u/AppleII717)\
**Post date:** [September 27, 2010, 2:36pm UTC](https://discuss.rubyonrails.org/t/polymorphic-associations/54648/2 "2010-09-27T14:36:10Z")

</div>

I think @image.imageable returns an ActiveRecord Object, which you can't just display. If you are just testing:

@image.imageable.inspect should dump the active record object the image is related to.

If you are trying to get an attribute of the imageable relation, since there can be different relations you have to use the imageable\_type to make sure it is there and use something like @image.imageble.name

---

<div class="post-metadata">

**Author:** ![radhames\_brito](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@radhames\_brito](https://discuss.rubyonrails.org/u/radhames_brito)\
**Post date:** [September 27, 2010, 3:41pm UTC](https://discuss.rubyonrails.org/t/polymorphic-associations/54648/3 "2010-09-27T15:41:37Z")

</div>

But does the image an imageable? how are you saving the image?

---

<div class="post-metadata">

**Author:** ![AppleII717](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/appleii717/32/3905_2.png) [@AppleII717](https://discuss.rubyonrails.org/u/AppleII717)\
**Post date:** [September 27, 2010, 5:45pm UTC](https://discuss.rubyonrails.org/t/polymorphic-associations/54648/4 "2010-09-27T17:45:06Z")

</div>

I was just talking about polymorphic in general. For images I'd use something like paperclip.

[http://github.com/thoughtbot/paperclip](http://github.com/thoughtbot/paperclip)

Then you'd have something like

class Image \< ActiveRecord::Base &nbsp;&nbsp;include Paperclip &nbsp;&nbsp;belongs\_to :imageable, :polymorphic =\> true &nbsp;&nbsp;has\_attached\_file :photo, &nbsp;&nbsp;&nbsp;&nbsp;:styles =\> { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:thumb=\> "100x100", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:small =\> "200x200\>", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:medium =\> "300x300\>", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:large =\> "400x400\>" }

end
