默认图像未显示回形针

时间:2014-10-23 01:08:38

标签: ruby-on-rails ruby-on-rails-4 paperclip

我的默认图片在尝试加载时被破坏了。

我的代码:

has_attached_file :background, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "default-logo.png"
validates_attachment_content_type :background, :content_type => /\Aimage\/.*\Z/

渲染:

Failed to load resource: the server responded with a status of 404 (Not Found) http://test.dev/default-logo.png

default-logo.png位于我的assets/images文件夹中。为什么现在出现?

1 个答案:

答案 0 :(得分:2)

您需要在has_attached_file代码行中明确设置路径,以告知Paperclip 正好在哪里查找您的默认图片。我过去使用的是ActionController::Base.helpers.asset_path,传入资产文件名。

因此,对于您的代码,请尝试:

has_attached_file :background, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => ActionController::Base.helpers.asset_path("default-logo.png")
相关问题