nee*_*zer 39 ruby plugins ruby-on-rails paperclip
如果没有图像与记录关联,如何防止调用关联图像的图像标记?
<%= image_tag @agent.avatar.url %>
Run Code Online (Sandbox Code Playgroud)
...如果没有与该代理相关联的图像,则会向我显示"Missing"文本.我想先测试看看是否有可用的图像,然后如果测试返回true则渲染上面的标记.
更好的是,如果没有专门提供图像,我还有指定默认图像吗?
Chr*_*ssl 60
我使用以下内容来查找模型是否具有相关附件:
<% if @agent.avatar.file? %>
<%= image_tag @agent.avatar.url(:normal) %>
<% else %>
No attachment available!
<% end %>
Run Code Online (Sandbox Code Playgroud)
Vol*_*ldy 53
如果头像有多种尺寸:
has_attached_file :avatar,
:styles => {:small => '30x30#', :large => '100x100#'},
:default_url => '/images/missing_:style.png'
Run Code Online (Sandbox Code Playgroud)
for Rails 3:
has_attached_file :avatar,
:styles => {:small => '30x30#', :large => '100x100#'},
:default_url => '/assets/images/missing_:style.png'
Run Code Online (Sandbox Code Playgroud)
nee*_*zer 31
好的,所以我得到了它的一部分.
指定默认图像发生在模型中
has_attached_file :avatar, :default_url => '/images/brokers/agents/anonymous_icon.jpg'
Run Code Online (Sandbox Code Playgroud)
tig*_*tig 18
少了几个字节:
<% if @agent.avatar? %>
<%= image_tag @agent.avatar.url(:normal) %>
<% else %>
No attachment available!
<% end %>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17093 次 |
最近记录: |