paperclip where to place the missing.png default image?

前端 未结 2 1661
日久生厌
日久生厌 2021-01-19 03:53

I use paperclip in my app, but my controller tests are failing because of:

BlogsControllerTest#test_should_update_blog:
Paperclip::AdapterRegistry::NoHandle         


        
相关标签:
2条回答
  • 2021-01-19 04:47

    For this line of code:

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

    Paperclip is looking for images under /public/images/default_image.png

    update:

    so you have defined style big and thumb. Paperclip will look for img in public/images/thumb/default_image.png or public/images/big/default_image.png depending what style will you call in <% image_tag @model.image.url(:style) %>.

    update #2 (according to update #4 from author's question)

    gotcha! If you want model to use :default_url don't send :image in params. remove image from params and lets see how it goes`

    0 讨论(0)
  • 2021-01-19 04:48

    In Rails 5, I managed to work using :style in the path:

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

    and if, for example, this image doesn't exist:

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

    the result is

    /images/folder/medium/missing.png
    
    0 讨论(0)
提交回复
热议问题