0

I have was seeing several discussions (on stackoverflow here and here, and as a bug on paperclip here) around the best way to tell the default_url of images using Paperclip and Rails so that they work fine in production with the asset pipeline. All solutions appear quite complicate.

Is there anything wrong in putting the default images in the public/ directory of the Rails app? Anything I need to worry down the line or that I am missing?

If I put images in the public/ directory and access them with the code below all appears to work correctly.

has_attached_file :image, 
  styles: {original: "1000x1000", medium: "530x530#", thumb: "300x300#"}, 
  default_url: "/default-avatar_:style.png"
Community
  • 1
  • 1
Andrea
  • 143
  • 1
  • 2
  • 7

1 Answers1

0

I generally, by convention alone include the missing styles images in the assets directory. You don't need any extra coding or complex mechanisms to have paperclip utilize them.

#Images within assets:
/app/assets/images/default-avatar_original.png
                   default-avatar_medium.png
                   default-avatar_thumb.png


# paperclip config in /app/models/user.rb
has_attached_file :image, :styles => {:original => ["1000x1000", :png],
                                       :medium   => ["530x530#", :png], 
                                       :thumb    => ["300x300#", :png] }, 
                :default_url => "/assets/default-avatar_:style.png"

Note that when specifying default_url, you exclude the /image/ directory.

Venice
  • 1,858
  • 1
  • 11
  • 10