问题描述
我正在创建用户头像.我无法显示missing.png".对于决定不上传个人资料图片的用户,我创建了一个要显示的默认图片.以下是我到目前为止所得到的.请告诉我我做错了什么.
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(目前显示所有用户的所有帖子)
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(这是用户的个人资料页面)
users/show.html.erb (This is the user's profile page)
<%= image_tag @user.avatar.url(:medium) %>
missing.png"
图片:app/assets/images/missing.png
拇指:app/assets/images/thumb/missing.png
媒体:app/assets/images/medium/missing.png
大:app/assets/images/large/missing.png
我做错了什么?
推荐答案
代替:
default_url: "/images/:style/missing.png"
试试:
default_url: "/:style/missing.png"
这篇关于Ruby/Paperclip:如何让 missing.png 工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!