How show hide image in paperclip when no image present How show hide image in paperclip when no image present ruby-on-rails ruby-on-rails

How show hide image in paperclip when no image present


I use the following to find wether a model has an associated attachment:

<% if @agent.avatar.file? %>  <%= image_tag @agent.avatar.url(:normal) %><% else %>  No attachment available!<% end %>


If avatar has multiple sizes:

has_attached_file :avatar,                   :styles => {:small => '30x30#', :large => '100x100#'},                   :default_url => '/images/missing_:style.png'

for Rails 3:

has_attached_file :avatar,                   :styles => {:small => '30x30#', :large => '100x100#'},                   :default_url => '/assets/images/missing_:style.png'


Okay, so I got one part of it.

Specifying a default image happens in the model

has_attached_file :avatar, :default_url => '/images/brokers/agents/anonymous_icon.jpg'