I have a model with a Boolean checkbox, and when it is clicked ‘true’ I would like to display the image, and if not clicked ‘null’ would like to display absolutely nothing.
So far the view is called as:
<%= image_tag(@dining.pets? ? 'petfriendly.png' : '', :title => 'Pet Friendly', :alt => 'Pet Friendly') %>
The empty tick ” was my attempt at nothing, but it just gives me a broken link image. As this is my personal attempt at working this out and I’m relatively new to rails, I am not sure if an if/else in long form is a good way to go about this?
Any ideas? Thanks!
This might be a tad shorter syntax.
<%= image_tag('petfriendly.png', :title => 'Pet Friendly', :alt => 'Pet Friendly') if @dining.pets.present? %>Also, nice use of :alt attribute; the seeing impaired will appreciate it.