Add conditional class names
If you want to conditionally add class names in Rails, here is a clean way to do it.
<%= link_to("Some Page", some_path,
class: class_names("bg-black text-black", {"text-white": text_visible?})
%>
This takes advantage of the class_names
method, which is just an alias for the token_list method.
h/t to Matt Polito.
I always find myself looking up his TIL and figured if I make it myself it will help me retain it. 😅