我刚刚安装了paper_clip,允许用户上传个人资料图片,可以很容易地显示与:
<%= image_tag @user.profile_pic.url %>我现在好奇的是如何处理没有上传profile_pic的用户。如何显示标准站点用户图像(通用)
我应该做个帮手吗?
像showProfilePic(@user, size)这样的东西
然后使用该助手显示合适大小的图像,无论是用户上传的照片还是通用网站的个人资料图片?
谢谢。有没有现成的助手?
发布于 2010-10-11 02:57:31
您可以使用default_url和default_style选项来设置它。默认的附件是/: default_url /: style / missing.png,所以你可以为每种风格插入missing.png,并让它成为你的通用头像。但是,如果您想要自定义...
class User < ActiveRecord::Base
has_attached_file :profile_pic,
:default_style => :thumbnail,
:default_url => '/path/to/:style_default.jpg'
endhttps://stackoverflow.com/questions/3901642
复制相似问题