仅显示图像(如果可用)

时间:2014-02-11 23:10:51

标签: ruby-on-rails paperclip

如何编辑下面的代码,如果没有@ business.logo可用,则没有代码。

= image_tag @business.logo(:thumbnail), :class=> "img-rounded"

当前没有上传图片时显示:

<img alt="Thumbnail" class="img-rounded"   src="http://s3.amazonaws.com/callred/businesses/logos/000/000/034/thumbnail/">

2 个答案:

答案 0 :(得分:2)

= image_tag(@business.logo(:thumbnail), :class=> "img-rounded") if @business.logo

更新

应该问if @business.logo.present?

@business.logo返回始终为真的Paperclip::Attachment对象

答案 1 :(得分:1)

知道了!这是适合我的代码

- if @business.logo.present?
  = image_tag @business.logo(:thumbnail), :class=> "img-rounded"