Reputation: 312
This is my code:
:styles => lambda { |attachment| attachment.instance.define_styles }
def define_styles
return_styles = Hash.new
case self.imageable_type
when "Admin::ProductDetail"
return_styles[:thumb] = "70x60>"
return_styles[:front] = "450x400>"
else
end
return_styles
end
The problem is that when I first upload the image, it dont use the styles... only after I reupload the image, so it is only creating the default style, not the :thumb or :front in the first upload.
Upvotes: 1
Views: 309
Reputation: 312
I added this code and it works now.
after_create :reprocess
def reprocess
self.image.reprocess!
end
But I don't know if it's the right way to do it.
Upvotes: 1
Reputation: 29349
You can use the callback before_post_process
:styles => lambda { |attachment| attachment.instance.define_styles }
before_post_process :skip_on_create
def skip_on_create
!new_record?
end
When this callback returns false, the post processing step will be halted
Documentation here
Upvotes: 1