I have set up my models to use a polymorphic Image model. This is working fine, however I am wondering if it is possible to change the :styles setting for each model. Found some
the :styles
property takes a Proc
as argument, so you can do all kinds of fancy stuff :)
class Image < AR::Base
has_attached_file :file, :styles => Proc.new { |a| a.instance.file_styles }
def file_styles; { :thumb => "150x150>", :normal => "492x600>" } end
end
class Didum < Image
def file_styles; { :thumb => "50x50>", :normal => "492x600>" } end
end
Note - the above code should work, but honestly I have no setup to verify it, but looks like the Paperclip::Attachment#styles
does call
if it responds to it, see http://rdoc.info/github/thoughtbot/paperclip/master/Paperclip/Attachment:styles
UPDATE the object passed into the Proc
is not the instance, but the Paperclip::Attachment
, but the instance is accessible through instance
on the attachment
PS: And I've seen this in some other places, but can't remember where...