If you find yourself putting ternary conditions in templates to switch CSS classes for an element, e.g.
<%= tag.div(class: user.active? ? "active block" : "block") do %>
Try Rails 6.1's token_list
(https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-token_list) which is built into the tag
helper (https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-tag):
<%= tag.div(class: ["block", "active" => user.active?]) do %>
=> More informations about this toot | More toots from mudge@ruby.social
@mudge I find the class_names
alias easier to remember due to the similarity with the JS package...
https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-class_names
=> More informations about this toot | More toots from floehopper@ruby.social This content has been proxied by September (ba2dc).Proxy Information
text/gemini