Simpler conditional HTML classes with class_names

Coming from JS and React you may be familiar with a package called `classnames`. It takes an object where the keys represent CSS classes, and the values are booleans which determine if the key should be loaded or not.

Eg. classnames('foo', { bar: true, baz: false })

Returns: 'foo bar'

Rails includes its own helper which does this same thing. You can call `class_names` or `token_list`:

Eg. class_names('foo', { bar: true, baz: false })

Returns: 'foo bar'

douglasgreyling
October 4, 2022