J'utilise de papier pour télécharger toutes sortes de fichiers (documents texte, binaires, images).
J'aimerais mettre cela dans mon modèle: p>
if :attachment_content_type =~ /^image/
3 Réponses :
Vous pouvez utiliser voir la section "Evénements" dans DOCS P> avant_
FALSE code> dans le rappel, il n'y aura aucune tentative d'utilisation des styles.
before_attachment_post_process :allow_only_images
def allow_only_images
if !(attachment.content_type =~ %r{^(image|(x-)?application)/(x-png|pjpeg|jpeg|jpg|png|gif)$})
return false
end
end
Peut-être que vous avez besoin de quelque chose comme ceci: et définir la méthode dans votre modèle: p> def image?
attachment.content_type.index("image/") == 0
end
Vous pouvez utiliser sur votre modèle
`has_attached_file :avatar, :styles => lambda { |a| if a.content_type =~ %r{^(image|(x-)?application)/(x-png|pjpeg|jpeg|jpg|png|gif)$} { :thumb => "100x100#", :medium => "300x300>", } else Hash.new end },:default_url => "/missing.png"`