Rails Paperclip 在本地上传没有问题,在服务器上出现错误

autumnwolf · 2014年03月26日 · 最后由 autumnwolf 回复于 2014年03月27日 · 1758 次阅读

如题,

ActionController::RoutingError (No route matches [GET] "/photos/small/missing.png"):
  actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.2) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.2) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.2) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.2) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.0.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.2) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'

Picture.rb

class Picture < ActiveRecord::Base
  belongs_to :product

  has_attached_file :photo, :styles => { :small => "200x200>", :large => "400x400" },    
  :url => "/assets/products/:id/:style/:basename.:extension",    
  :path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"

  validates_attachment_presence :photo    
  validates_attachment_size :photo, :less_than => 5.megabytes    
  validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png'] 
end

这个错误是找不到 missing.png, 但是我没有设定 default_url, 应该是没有上传文件的时候有调用这个文件吧?什么情况下出现的这个错误呢?谢谢。

Assets Pipeline 引起的,具体是发布的时候,small.png 变成其他文件名了

这个你可以查查 Paperclip Assets Pipeline 的问题

Paperclip 在 Github 的 Issues 里面估计就有解决方案

#1 楼 @huacnlee 谢谢 刚找到了就是有个缩略图显示,没有上传图片然后添加的时候就会加载一个 missing.png 添加上就好了

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册