user1724295
user1724295

Reputation:

Only show image if it's available

How can I edit the code below, so there's no code if no @business.logo is available.

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

This shows up currently when no image has been uploaded:

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

Upvotes: 0

Views: 79

Answers (2)

Zoki
Zoki

Reputation: 121

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

update

should ask if @business.logo.present?

@business.logo returns Paperclip::Attachment object which is always true

Upvotes: 2

user1724295
user1724295

Reputation:

Got it! Here's the code that worked for me

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

Upvotes: 1

Related Questions