I use paperclip in my app, but my controller tests are failing because of:
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'
I'm not sure where I should place the missing.png
image in my code, I tried in public/assets/original/missing.png
but it doesn't seem to manage it.
Also there's something odd: I have a paperclip.rb
initializer line:
Paperclip::Attachment.default_options[:default_url] = "/images/default_image.png"
but still the app is looking for the missing.png
UPDATE: ok I figured that the default_url was overridden in the model:
has_attached_file :image, styles: { big: "1200X630>", thumb: "150X150" }, default_url: "/images/:style/missing.png"
I still don't know where to place the image.
UPDATE2:
the entire paperclip initializer:
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: checking the paperclip code that actually rises the code, the exception is risen by this piece of code, which is basically testing all the adapters available, the one that looks like the closest to what I want to do is the fileAdapter
which tests if the string passed is a File.
I'm quite surprised from finding this, I thing I might be getting something wrong here. If I exchange the initializer line to:
Paperclip::Attachment.default_options[:default_url] = File.new "public/images/missing.png"
then the exception is different:
BlogsControllerTest#test_should_update_blog:
NoMethodError: undefined method `gsub' for #<File:public/images/missing.png>
/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: this is what the test looks like:
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
then:
@blog.image.class
=> Paperclip::Attachment
@blog.image.url
=> "/images/missing.png"
:default_url
is commonly used ;) – Bashkir*
in the default_url string? how will it know which image from that path to pick? – Jacquez:image
in params. removeimage
from params and lets see how it goes`\ – Bashkirpaperclip.rb
, but it says in the model:has_attached_file :attachment
and no default_url overridden. Why is the image displayed as a link tomissing.png
and not as the png itself? – Publicize