RubyUI (Former PhlexUI): Ruby Gem for RubyUI Components
38 comments
·April 1, 2025GenericCanadian
freedomben
I increasingly wonder if I'm the only one left who genuinely likes erb :-D
Not a fan of the rails erb helper methods though, so maybe it doesn't count. I almost exclusively use it outside of rails now
barefootford
I don't know if I'm a fan but I've almost never had erb be the problem in a Rails app. The LLMs can work with it easily. Don't need to bring in extensions to work with major text editors. Sticking with ERB for now.
GenericCanadian
I found using partials between projects to be a headache. I wanted a way to standardize my UI for accessibility across all projects and not have to re-implement the same standards over and over. It's nice to be able to package the UI up into a gem and keep it maintained everywhere.
It's got a nice path for incremental adoption, so there is no need to go all-in unless you want to. Personally my Rails projects are all 95%+ ruby now.
Another nice knock off effect is that the LSP and integration with my IDE (neovim) is much nicer with Phlex components than it is with ERB.
I also think personally I don't like "magic" spaces like ERB where its hard for me to follow the code path. How does ERB manage multiline blocks with html in them? Hard to understand, harder to explain. To me it feels like there is less to worry about in Phlex where I'm thinking more in Ruby, less in the specifics of the view context.
jherdman
Have you had much luck with slots? I have a project using View Components that leverages slots. I've tried migrating to Phlex, but the lack of explicit slot support has been a bit frustrating.
GenericCanadian
Slots are pretty easy in Phlex. Have a look at the README in the repo I linked for an idea. I just create `with_column` or `with_header` methods that take a block and store it.
To create them declaratively (not needing to call them in a set order) you just create a module that defines `before_template` and calls `vanish`: https://www.phlex.fun/miscellaneous/v2-upgrade.html#removed-...
budu
The RubyUI team is doing a fantastic job. This gem is now one of the first ones I add to a new project. Thanks for your work!
bdcravens
Looks interesting, but I wish there was a way to alias the component names, since every component class, some of which have common names, take root in the global namespace. (though I suspect that easily enough done manually)
joeldrapper
They’re not in the root namespace. They are instance methods (on the instance of the component) that start with a capital letter. https://www.phlex.fun/components/kits.html
anonygler
I used a rendering library like Phlex back in 2010. I hated it back then and I still don’t like it.
They claim it’s faster than ERB but only show micro benchmarks. This is basically a form of lying.
This approach stinks for a lot of reasons:
- it adds a ton of pressure on the garbage collector. - the backtraces suck to debug. Ruby is better now than in 2010, but it’s still lame. - your templates are largely static. Yet when it lives as code you can’t cache any of it. An efficient ERB generator is just cached strings concatenations. Very efficient in Ruby.
Finally, Rubyists hate this and it’s why the community is slowly dying. Almost all your frontend should be in JS/JSX at this point. Even the static stuff.
joeldrapper
This is nonsense. You can cache it like anything else. But you probably won’t need to because it’s so fast.
drumpkid
I’m impressed by this project’s progress. It’s more than just a render library. Although they claim it’s 12x faster than ERB, but I couldn’t find their benchmark.
fidrelity
I believe it's referencing this: https://github.com/KonnorRogers/view-layer-benchmarks
byroot
Can't believe this still has to be debunked. No Phlex certainly isn't 12x faster than ERB. It's noticeably slower than ERB, e.g.: https://github.com/KonnorRogers/view-layer-benchmarks/commit...
In some extreme scenarios with tons of very small partials, it can win against Action View because the Action View partial lookup is significant overhead.
joeldrapper
In my experience, it’s not an extreme scenario to render several thousand components in a single view.
I think you’re looking at this from the perspective of having maybe a partial for your header and another for your footer. The way you build views in Phlex is you would have a component not just for the header but also the nav, each item in the nav, and each icon in each item.
We can argue about whether that level of abstraction and reuse is worth it, but the fact is ActionView gets very slow when you build views like that composing thousands of partials — and for people who want to build views like that, it matters.
Still, I think these “12× faster” comparisons are silly. If ActionView was just as fast at rendering thousands of small components, I’d still pick Phlex for the developer experience. I enjoy writing Ruby, not toggling between Ruby and HTML.
tenderlove
It says on the website it's 12x faster so it must be true!
mrinterweb
There were a few things off about the benchmarks so I made a pull request with some updates. The 12x claim is WAY off. https://github.com/KonnorRogers/view-layer-benchmarks/pull/2...
alexmccain6
RubyUI looks interesting, but I wonder how well it scales in large apps. Moving away from ERB makes sense for maintainability, but does it introduce any trade-offs in terms of memory usage or debugging? Would love to hear from people using it in production.
daviding
Interesting stuff. Unsure about the Phlex approach but could be worth a go.
Didn't have any luck with the Date Picker component demo page (no pop up or validation?), and that's my usual go-to for seeing how these libraries are doing.
jspash
Just curious why the decision was made to go with PascalCase for the DSL? Is this meant to help React devs feel at home? Seems very un-Rubylike.
joeldrapper
It’s because that’s how constants are named in Ruby. The method names match the constant names of the component classes.
dragonwriter
methods aren't constants and the normal ruby idiom if there was a reason for method names to correspond to class/constant names in a different module would be for the method names to be the constant name converted from PascalCass to snake_case, rather than the method names being in the format of constant names.
dzonga
this looks dope. has anyone built anything substantial with phlex ?
allknowingfrog
I haven't done anything with RubyUI, but I've been using Phlex for the past couple of months and I never want to go back. It's everything I wanted HAML or Slim to be. Everything is code. You create classes and functions instead of views and partials. Everything you know about managing and abstracting code suddenly applies to your UI rendering.
Paired with Tailwind, this is the fastest application development I've ever done.
joeldrapper
I believe Clearscope is the largest app using Phlex views exclusively, with 454 components and counting. There’s a list of some other users here. https://www.phlex.fun/project/community.html#who-s-using-phl...
timwis
Yep! https://magicnotes.ai It’s pretty neat once you get over the initial weirdness. Unlocks a lot of potential. But because it’s new, there are fewer conventions, so you have to come up with them and be consistent.
aliosm
I’m using Phlex/RubyUI primarily in my project https://baheth.ieasybooks.com and it is amazing in both performance and developer experience.
ajmaia
Our team was already using the pre-release version in the current project, a brand new Rails 8 monolith. Its being very useful!
justinko
If I can't copy/paste HTML, not interested.
joeldrapper
There is an experimental feature that allows you to use ERB templates like ViewComponent. https://github.com/phlex-ruby/phlex/pull/867
cbeltrao
Awesome project!
Phlex is an amazing project. Makes frontend fun again. I've built my own UI library using DaisyUI and Tailwindcss that we use in all our Rails projects: https://github.com/inhouse-work/protos
It cannot be overstated how nice it is to move away from erb and into pure ruby. Private methods as partials is a game changer for refactoring your UI.