【问题标题】:viewing of paperclip attachment not working查看回形针附件不起作用
【发布时间】:2017-03-22 18:14:36
【问题描述】:

我已经使用代码上传了一个文件 images.jpeg <%= s.file_field :job_offer %> 。上传很好,但是当尝试使用代码link_to "View" , @job.job_offer.url 查看上传的文件时,它会抛出错误。日志文件中没有任何内容。此外,所有其他具有相同类型代码的地方都可以正常工作。

当我检查网络错误时,它显示Failed to load resource: the server responded with a status of 500 (Internal Server Error)。在响应头中,类型为Content-Type:text/html。如果这将是问题,如何解决这个问题?

我试过在链接中给出 type = 'image/jpeg' ,但还是一样。有没有其他方法可以输入类型?

模型.rb

  has_attached_file :job_offer,
                :url => "/uploads/:class/:id/:attachment/:attachment_fullname?:timestamp",
                :path => "uploads/:class/:attachment/:id_partition/:style/:basename.:extension"

在架构中,

t.string   "job_offer_file_name"
t.string   "job_offer_content_type"
t.integer  "job_offer_file_size"

【问题讨论】:

    标签: ruby-on-rails ruby paperclip


    【解决方案1】:

    要显示图像,您需要使用下面的图像标记语法:

    <%= link_to root_path do %>
        <%= image_tag "image_path", class: "some css class here" %>
    <% end %>
    

    或

    <%= link_to( image_tag(@job.job_offer.url), jobs_path, :class=>"abc") %>
    

    【讨论】:

    • 但它不会总是图像。可以上传任何类型的文件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多