在 Paperclip 中指定 missing.png [英] Specifying missing.png in Paperclip
问题描述
我正在使用 Paperclip 处理我的应用程序中的个人资料照片上传.他们上传得很好并调整到我模型中的规格.但是,如果用户的个人资料 :photo 为零,无论我尝试什么,我都无法更改默认设置.这是我要使用的代码:
<% 如果@profile.photo.nil?%><%= image_tag "public/images/example.jpg", :html =>{ :id =>"noUserProfile" } %><%其他%><%= image_tag @profile.photo.url(:normal) %><%结束%>
我已经尝试过../public/images/example.jpg",但即使我的公共图片文件夹中有example.jpg",这也不起作用.当我在视图中复制图片地址时,我得到:
http://localhost:3000/photos/normal/missing.png
我将这些文件夹添加到我的应用程序中,并在其中放置了一个 missing.png 文件,但什么也没有.如果我转到上面的 URL,我得到 No route matching "/photos/normal/missing.png"
有人知道发生了什么吗?
配置文件模型中的has_attached_file:
has_attached_file :photo,:styles =>{:正常=>"153x220#",:小 =>"75x108#" }
add_attachment_photo_to_profile 迁移:
class AddAttachmentPhotoToProfile <ActiveRecord::迁移def self.upadd_column :profiles, :photo_file_name, :stringadd_column :profiles, :photo_content_type, :stringadd_column :profiles, :photo_file_size, :integeradd_column :profiles, :photo_updated_at, :datetime结尾def self.downremove_column :profiles, :photo_file_nameremove_column :profiles, :photo_content_typeremove_column :profiles, :photo_file_sizeremove_column :profiles, :photo_updated_at结尾结尾
这是在 :photo
存在时呈现的 HTML:
<div class="smFrame"><div class="smUserPhoto"><img alt="8217_667699353137_15600054_38423586_7789442_n" src="/system/photos/1/small/8217_667699353137_15600054_36842054_3842053_3684253137_868427589584275895842735894427538894427538894427789427894278942788427894588942778942778942778942789442782张照片
<div class="findinfo"><p><a href="/profiles/1">姓名</a></p>
这是当 :photo
为零时呈现的 HTML:
<div class="smFrame"><div class="smUserPhoto"><img alt="Missing" src="/photos/small/missing.png"/>