rails/rails — Issue #4725: Rails helpers could ignore HTML attributes which equal false
Author: slainer68
Created: 2012-01-27 16:43:10+00:00
State: open

Currently Rails helpers only ignore HTML attributes which are nil :

```erb
<%= content_tag(:span, "element", class: nil) %>

```

Often you want to apply a particular class or id only if some condition is true, for example in navigation links. If this case you'll have to use the ternary operator like :

```erb
<%= content_tag(:span, "element", class: element.active? ? "active" : nil) %>
```

In HAML there is a feature where an attribute is also ignored when it equals false, so the line bellow can simply be written :

```haml
%span{ class: element.active? && "active" } element
```

Currently, Rails helpers output the attribute value "false". What do you think of copying the HAML behaviour for all Rails helpers ?