5 Followers
29 Following
20 Posts

Not sure how well known, but rails has a helper called token_list (also aliased as class_names).

Super helpful when you're writing conditional stuff a lot, especially HTML classes.

Very similar to clsx, etc. in the JS ecosystem.

Alias it to `cx` to make it even shorter.

#rails #tailwind

If you use VSCode and have a lot of View Components, configuring explorer.fileNesting might clean up your `app/components` in the explorer a lot:

"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"*_component.rb": "_${capture}_component_*.html.erb, ${capture}_component.html.erb, ${capture}_component.js, ${capture}_component_controller.js, ${capture}_component.scss"
},

#rails #viewcomponent #vscode

I've always felt rendering ViewComponent with Rails is a bit too verbose.

Especially if you have namespaces. E.g:

render(Admin::Navigation::Item.new(label: 'Example'))

I've used a helper to make it nicer on 2 projects so far:

vc.admin.navigation.item(label: 'Example')

Maybe make it into a gem?

(Might seem a bit over-engineered on a first glance. But it's something that might be called 100s-1000s of time on a page, so had to make sure it's fast enough.

#rails #ruby #ViewComponent