# Attachment\_fu, polymorphism and customization

**URL:** <https://www.ruby-forum.com/t/attachment-fu-polymorphism-and-customization/138859>\
**Category:** Rails\
**Created:** [May 28, 2008, 1:26pm UTC](https://www.ruby-forum.com/t/attachment-fu-polymorphism-and-customization/138859 "2008-05-28T13:26:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [May 28, 2008, 1:26pm UTC](https://www.ruby-forum.com/t/attachment-fu-polymorphism-and-customization/138859/1 "2008-05-28T13:26:01Z")

</div>

Hi,

I got Image model that has\_attachment and belongs\_to 2 other models  
via polymorphic association.  
The problem is that I’d like to customize has\_attachment options  
(resize image) depending on which model the Image is related to - i.e.  
if Image belongs to Article it should be resized using different  
settings than if it belongs to Header.

Is there a smart way to do it or do I have to create 2 separate Image  
models?

---

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [May 28, 2008, 3:00pm UTC](https://www.ruby-forum.com/t/attachment-fu-polymorphism-and-customization/138859/2 "2008-05-28T15:00:55Z")

</div>

On May 28, 1:25 pm, szimek [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> models?  
> Got it. In Image model:

before\_validation :modify\_parent\_options

protected  
def modify\_parent\_options  
if self.image? && self.parent\_id.nil?  
case self.attachment\_type  
when ‘Article’  
self.attachment\_options[:resize\_to] = ‘400x300\>’  
end  
end  
end
