问题
I am creating user avatars. I am having trouble getting the "missing.png" to show up. For users who decided not to upload a profile picture, I have created a default image to be displayed. Below is what I got so far. Please show me what I am doing wrong.
user.rb
has_attached_file :avatar, styles: { large: "800x800>", medium: "300x300>", thumb: "50x50>" }, default_url: "/images/:style/missing.png"
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
posts/index.html.erb (Shows all posts by all users, for the moment)
<%= link_to(image_tag(post.user.avatar.url(:medium)), user_path(post.user.username)) %>
users/show.html.erb (This is the user's profile page)
<%= image_tag @user.avatar.url(:medium) %>
"missing.png"
Images: app/assets/images/missing.png
Thumb: app/assets/images/thumb/missing.png
Medium: app/assets/images/medium/missing.png
Large: app/assets/images/large/missing.png
What am I doing wrong?
回答1:
Instead of:
default_url: "/images/:style/missing.png"
Try:
default_url: "/:style/missing.png"
来源:https://stackoverflow.com/questions/38734116/ruby-paperclip-how-to-get-missing-png-to-work