Rails class_names helper

class_names is a neat helper method for CSS class names.

It merges the class names list into a string, supporting optional conditions. Very similar to the classNames JS function.

The example from the PR demonstrates the way a new helper improves readability for a conditional class names generation in a view:

Before:

<div class="<%= item.for_sale? ? 'active' : '' %>">

After:

<div class="<%= class_names(active: item.for_sale?) %>">

class_names is an alias to the more generic token_list that must be a semantic generalization for non-CSS use cases.

References:



Somewhat related: