Ruby/Paperclip: How to get missing.png to work? [duplicate]

你离开我真会死。 提交于 2019-12-12 03:18:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!