Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 默认图像不会与回形针一起显示_Ruby On Rails_Ruby On Rails 4_Paperclip - Fatal编程技术网

Ruby on rails 默认图像不会与回形针一起显示

Ruby on rails 默认图像不会与回形针一起显示,ruby-on-rails,ruby-on-rails-4,paperclip,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/

我的默认图像在尝试加载时被破坏

我的代码:

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
文件夹中。为什么现在会显示?

您需要在
has\u attached\u文件
代码行中显式设置路径,以告诉回形针在何处查找默认图像。我过去使用的是
ActionController::Base.helpers.asset\u path
,传入资产文件名

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

has_attached_file :background, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => ActionController::Base.helpers.asset_path("default-logo.png")
可能重复的