Ruby on rails 用于PDF和图像的Rails回形针?
我想让用户能够上传PDF或图像。我知道只有处理图像时才有处理图像和pdf的方法吗 我能做到这一点 内柱模型:Ruby on rails 用于PDF和图像的Rails回形针?,ruby-on-rails,pdf,paperclip,Ruby On Rails,Pdf,Paperclip,我想让用户能够上传PDF或图像。我知道只有处理图像时才有处理图像和pdf的方法吗 我能做到这一点 内柱模型: 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/vn
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)}
在控制台中:
bin/rails g paperclip post attachment
如果是图像,那么我可以在视图中执行此操作
=image_tag post.image.url(:medium)
# It is haml syntax
但是,如果下载链接是pdf或word文件,我该如何显示它呢?如果不是图像,请使用:original而不是:medium。您可能需要为较新的word格式覆盖检测到的MIME类型,因为它们被检测为zip文件。我应该在视图文件中写入什么?是否仍要检查它是否为图像?您可以使用path检查它是否存在,或者使用mimetype检查,例如in、def image!(文件内容类型=~/^image\/.*/).nil?end不知道该如何制作代码块。。。