Ancestors

Toot

Written by mudge on 2024-09-19 at 08:31

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

Descendants

Written by James :ruby: on 2024-09-29 at 17:49

@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

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113163284455684453
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
261.683005 milliseconds
Gemini-to-HTML Time
0.335526 milliseconds

This content has been proxied by September (ba2dc).