下面是我的代码:
class Profile < ActiveRecord::Base
belongs_to :user
validates :first_name, presence: true
validates :last_name, presence: true
has_attached_file :avatar,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:default_url => ":style/missing.jpg"
validates_attachment_content_type :avatar, :content_type => /Aimage/.*Z/
end
此外,我的图像存储在应用程序/资产/图像/媒体中丢失.jpg在应用程序/资产/图像/拇指中存储为缺失.jpg。现在我得到的错误是它只显示单词丢失而没有图片。
下面是在我的视图文件中显示图片的代码。
<div class="profile-image">
<%= image_tag @user.profile.avatar.url %>
</div>
尝试:
:default_url => "/images/:style/missing.jpg"
来源: https://github.com/thoughtbot/paperclip/blob/master/README.md#models