rails 3.0.3 check if boolean value is true

if this line works:

if item.active == true

then

if item.active

will also work. if item.active? works only if there is a method whose name is actually active?, which is usually the convention for naming a method that returns true or false.


This should work for you assuming item.active is truly a boolean value. Unless there is a method defined for item.active? your example will only return a no-method error.

<% if item.active %>
    <%= image_tag('on.png', :alt => "Active", :border => 0) %>
<% else %> 
    <%= image_tag('off.png', :alt => "Inactive", :border => 0) %>
<% end %>