查看回形针附件不起作用

时间:2017-03-22 09:52:21

标签: ruby-on-rails ruby paperclip

我使用代码上传了一个文件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',但仍然是一样的。还有其他方式给出类型吗?

model.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"

1 个答案:

答案 0 :(得分:0)

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

<%= 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") %>
相关问题