Rails 4, Paperclip on Heroku does not recognize broken image

problem with solving problems with pictures in my project.

Summary: Rilas 4 is hosted on Heroku using Paerclip with S3

The problem starts with using the previously used custom boot logic from S3. Image url looks like this: /profile_picture/:style_:image_hash. It works great with images that are there, but with images that do not have clips, still trying to gain access to the image that is not there, and the actual link looks like this: http://s3.amazonaws.com/project/profile_pictures/100h_.

 has_attached_file :picture,
                styles:          { :'53h' => '', :'100h' => '' },
                convert_options: {
                    :'100h' => '-gravity center -thumbnail 165x165^ -extent 165x165',
                    :'53h'  => '-gravity center -thumbnail 45x45^ -extent 45x45'
                },
                path:            'profile_pictures/:style_:filename',
                default_url:     '/images/default-pp-large.jpg'

I suppose this might be due to the style inside the actual file name, but I'm not sure if the Eather way defauly_urlis down and all the images are broken, except for the ones that are actually there.

You can help?

+4
2

. config/initializers/paperclip.rb

module Paperclip
  class Attachment
    alias_method :original_url, :url

    def url(style_name = default_style, options = {})
      if @instance.public_send("#{@name.to_s}_file_name").blank?
        'default-pp-large.jpg'
      else
        original_url(style_name, options)
      end
    end
  end
end
+3

wondring, ID , , 2 , , , :

path: 'profile_pictures/:id_:style_:filename'
# OR
path: 'profile_pictures/:id/:style_:filename'

, , .

+1

Source: https://habr.com/ru/post/1607496/


All Articles