This blog is part of our Rails 6.1 series.
Rails 6.1 adds class_names
view helper method to conditionally
add CSS classes.
accepts String, Hash and Array as arguments
and returns string of class names built
Before Rails 6.1,
conditional classes were added
by using conditional statements.
Let’s take an example of adding an
active class to navigation
link based on the current page.
Check out the
for more details on this.