[英]Rails Paperclip for both PDF and Image?
I wanted to make user able to upload either PDF or image . 我想让用户能够上传PDF或图像。 I know only for handling image is there anyway to handle both image and pdf?
我只知道处理图像,无论如何都可以处理图像和pdf?
I can do up to here 我可以做到这里
Inside Post Model: 内部帖子模型:
has_attached_file :image
validates_attachment_content_type :image, :content_type => {:content_type => %w(image/jpeg image/jpg image/png application/pdf application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document)}
In console: 在控制台中:
bin/rails g paperclip post attachment
If it is image then i can do this in view 如果它是图像,那么我可以在视图中执行此操作
=image_tag post.image.url(:medium)
# It is haml syntax
But how do i display download link if it is pdf or let say word file? 但是,如果是pdf或说word文件,我如何显示下载链接?
Use :original instead of :medium if it's not an image. 如果不是图像,请使用:original而不是:medium。 You probably need to overwrite the detected MIME type for newer word formats since they are detected as zip files.
由于较新的单词格式被检测为zip文件,因此您可能需要覆盖检测到的MIME类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.