I also had the same problem as you. No need to do extra coding for this, just add the following
has_attached_file :attachment, :styles => lambda{ |a| ["image/jpeg", "image/png", "image/jpg", "image/gif"].include?( a.content_type ) ? { :thumb=> "100x100#", :small => "150x150>", :medium => "300x300>", :large => "500x500>" }: {} }
Let me know if you need further explanation.
source share