On May 28, 1:25 pm, szimek
<szi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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?
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---