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")
可能重复的