最近我安装了Paperclip gem,我正努力让我的系统上的默认图像工作,我把图像文件放在里面assets/images/pic.png.
这是我的模型中的代码User:
has_attached_file :pic,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:default_url => 'missing_:avatar.png'
#:default_url => 'assets/images/avatar.png'
has_attached_file :attach
Run Code Online (Sandbox Code Playgroud)
这是我AddPicPaperClip迁移中的代码:
def self.up
add_column :users, :pic_file_name, :string
add_column :users, :pic_content_type, :string
add_column :users, :pic_file_size, :integer
add_column :users, :pic_updated_at, :datetime
add_attachment :users, :pic
end
def self.down
remove_column :users, :pic_file_name
remove_column :users, :pic_content_type
remove_column :users, :pic_file_size
remove_column :users, :pic_updated_at
remove_attachment :users, :pic
end
Run Code Online (Sandbox Code Playgroud)
为了在我的节目中显示图像,我有以下代码:
<%= image_tag @user.pic.url(:medium) %>
Run Code Online (Sandbox Code Playgroud)
你可以帮我找一个解决方案,以便在用户输入自己的个人资料图片之前显示默认图片吗?