RSSAmplifier

Blog

mentalized.net

The virtual home of Jakob Skjerning, an experienced web application developer, consultancy owner and grumpy geek

mentalized.netRSS feed ↗10 posts

Latest posts

Announcing Flowbite Components for Rails

We ‘re open sourcing our Flowbite component library, a set of view components, we’re using in Front Lobby , Skrift , and a bunch of other projects, both internal and external. These days there’s no shortage of UI kits for Rails. It seems everybody is building their own design system and selling a component library on top of it. We aren’t that ambitious; we just want a gem we can include in all our…

Announcing styr

Ever needed to run some maintenance task in your production environment? For me this always triggers a bunch of questions: What’s that hostname again? What user should I log in as? And where did we deploy the application? We ‘ve built styr to answer those questions and ease the pain. With styr launching a Rails console in your production environment is as simple as $ styr --target=production run…

One-off scripts on Heroku with Rails

Every so often you have a small script that needs to be run on your staging or production server, but committing and deploying the script on its own is just too much of a hassle. Luckily Rails and Heroku has a great solution for this. rails runner If you have a script in your application that needs to run in the context of your Rails application, you can run it via rails runner . For example,…

Don't use instance variables in partials

One of my favorite pet peeves is instance variables in partials. Unfortuntaly, I still encounter these in actual production code. I get it, it happens. You have a view template that needs cleaning up: # app/views/employees/show.html.erb ... < % @meetings.each do | meeting | %> A bunch of code to render a meeting <% end %> ... Easy enough, just extract some parts of it into a partial : #…

How to fix <code>ld: library not found for -lzstd</code> installing mysql2

I have a history of problems with installing the mysql2 gem, and this is just another chapter in that tale . If you receive a ld: library not found for -lzstd error when running bundler or otherwise attempt to install the mysql2 gem, this might be the solution. What I experienced I am using MacPorts and trying to install the mysql2 gem gave me the following error $ gem install mysql2 -v 0.5.6 ...…

Designing the API for a ViewComponent Input Group

I’ve been working on a set of form input components based on the ViewComponent library. Unfortunately I’ve been having problems deciding on an API I like and this post is my attempt to think it through publicly. The simple case The simplest case for an input group is something like <%= render ( InputGroup . new ( form , :name )) %> which should render something like <label for= "user_name" > Name…

Driving View Transitions with Hotwired/Turbo

View transitions between pages has been a reality on the web for quite a while now (at least in the browsers that support it). It has also been possible to use them with Turbo, albeit somewhat cumbersome , but that’s changed. Turbo now has built-in support for the View Transitions API as of version 8+. Opt in to view transitions in Turbo Drive First of all, ensure you’re using a browser with View…

Active Record STI and eager loading

This week has been … interesting. Not because of obvious geopolitical events, but because a client application started throwing weird errors; background processes failed in ways that weren’t possible and otherwise reliable cronjobs just didn’t do what they were supposed to; no failures or anything, they just didn’t process the records they were meant to. This particular application uses Single…

How to fix (some) UnknownError and InvalidArgumentError in Capybara

The other day, our headless system specs in a Ruby on Rails project started failing with a bunch of errors we hadn’t seen before. Mostly Selenium::WebDriver::Error::UnknownError: unknown error: failed to close window in 20 seconds but in some cases also Selenium::WebDriver::Error::InvalidArgumentError: invalid argument: 'handle' must be a string . Usually random errors in browser tests can be…

SimpleLocalize on Rails

When your application spans across multiple countries and languages, managing your translations using Rails’ default locale files in git becomes too cumbersome. We recently moved a clients Rails app to SimpleLocalize to give translators and developers a better workflow around translations. This is how we did it. The setup Rails 6 using I18n with the default backend spanning 7 different languages.…