Search code examples
ruby-on-railsrails-activestorage

using Image_tag, render an alternative if the load fail


I am using active storage with rails 5.2.4, my attached file is named photo, I want to render "default.jpg" if the loading of the image failed (for example the image got delete from the storage), thanks


Solution

  •     <%= image_tag'batman.png', alt: 'hello', :onerror => "this.src='hulk.png'"  %>