Rich Peck Answer, .
has_attached_file :file,
styles: lambda { |a| a.instance.check_file_type}
check_file_type
Ruby best pratice
def check_file_type
if is_image_type?
{:small => "x200>", :medium => "x300>", :large => "x400>"}
elsif is_video_type?
{
:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10, :processors => [:ffmpeg] },
:medium => {:geometry => "250x150#", :format => 'jpg', :time => 10, :processors => [:ffmpeg]}
}
else
{}
end
end
is_image_type? is_video_type? , .
def is_image_type?
file_content_type =~ %r(image)
end
def is_video_type?
file_content_type =~ %r(video)
end
validates_attachment_content_type :file, :content_type => [/\Aimage\/.*\Z/, /\Avideo\/.*\Z/, /\Aaudio\/.*\Z/, /\Aapplication\/.*\Z/]
, paperclip .