回形针放置missing.png默认图像的位置?

我在我的应用程序中使用paperclip,但我的控制器测试失败是因为:

BlogsControllerTest#test_should_update_blog: Paperclip::AdapterRegistry::NoHandlerError: No handler found for "/images/original/missing.png" /Users/user/.rvm/gems/ruby-2.1.2/gems/paperclip-3.5.2/lib/paperclip/io_adapters/registry.rb:19:in `handler_for' /Users/user/.rvm/gems/ruby-2.1.2/gems/paperclip-3.5.2/lib/paperclip/io_adapters/registry.rb:29:in `for' /Users/user/.rvm/gems/ruby-2.1.2/gems/paperclip-3.5.2/lib/paperclip/attachment.rb:96:in `assign' 

我不知道我应该将missing.png图像放在我的代码中,我在public/assets/original/missing.png尝试过,但它似乎没有管理它。

还有一些奇怪的事情:我有一个paperclip.rb初始化线:

 Paperclip::Attachment.default_options[:default_url] = "/images/default_image.png" 

但仍然应用程序正在寻找missing.png

更新:好的我认为在模型中覆盖了default_url:

 has_attached_file :image, styles: { big: "1200X630>", thumb: "150X150" }, default_url: "/images/:style/missing.png" 

我仍然不知道在哪里放置图像。

UPDATE2:

整个回形针初始化程序:

 Paperclip::Attachment.default_options[:styles] = { thumb: "100x100#", small: "200x200#", screen: "800x600#"} Paperclip::Attachment.default_options[:default_url] = "/images/missing.png" Paperclip::Attachment.default_options[:path] = ":rails_root/public/assets/:class/:attachment/:id_partition/:style/:hash.:extension" Paperclip::Attachment.default_options[:url] = "/assets/:class/:attachment/:id_partition/:style/:hash.:extension" Paperclip::Attachment.default_options[:hash_secret] = "XXXXXXXXXXXXXXXXX" Paperclip.registered_attachments_styles_path = "public/assets/paperclip_attachments2.yml" 

UPDATE3:检查实际上升代码的回形针代码,这段代码提出exception,基本上是测试所有可用的适配器,看起来最接近我想要做的是fileAdapter ,它测试是否传递的字符串是一个文件。

发现这一点我感到很惊讶,我可能会在这里遇到问题。 如果我将初始化线交换为:

 Paperclip::Attachment.default_options[:default_url] = File.new "public/images/missing.png" 

然后exception是不同的:

 BlogsControllerTest#test_should_update_blog: NoMethodError: undefined method `gsub' for # /Users/user/.rvm/gems/ruby-2.1.2/gems/paperclip-3.5.2/lib/paperclip/interpolations.rb:33:in `block in interpolate' /Users/user/.rvm/gems/ruby-2.1.2/gems/paperclip-3.5.2/lib/paperclip/interpolations.rb:32:in `each' 

UPDATE4:这是测试的样子:

  test "should update blog" do put :update, id: @blog, blog: { author_id: @blog.author_id, body: @blog.body, image: @blog.image, title: @blog.title } assert_redirected_to blog_path(assigns(:blog)) end test "should create blog" do assert_difference('Blog.count') do post :create, blog: { author_id: @blog.author_id, body: @blog.body, image: @blog.image, title: @blog.title } end assert_redirected_to blog_path(assigns(:blog)) end 

然后:

 @blog.image.class => Paperclip::Attachment @blog.image.url => "/images/missing.png" 

对于这行代码:

 Paperclip::Attachment.default_options[:default_url] = "/images/default_image.png" 

Paperclip正在/public/images/default_image.png下查找图片

更新:

所以你定义了风格bigthumb 。 Paperclip将在public/images/thumb/default_image.pngpublic/images/big/default_image.png查找img,具体取决于您在<% image_tag @model.image.url(:style) %>调用的<% image_tag @model.image.url(:style) %>

更新#2(根据作者提问的更新#4)

疑难杂症! 如果你想要使用模型:default_url不发送:image para中的:image 。 从params删除图像,让我们看看它是怎么回事

在Rails 5中,我设法使用路径中的样式

 Paperclip::Attachment.default_options[:default_url] = "/images/folder/:style/missing.png" 

如果,例如,此图像不存在:

 <%= image_tag @photo.picture.url(:medium) %> 

结果是

 /images/folder/medium/missing.png