RSSAmplifier

Blog

Adrien Siami

Software engineer, Ruby, Rails, Web and stuff.

blog.siami.frRSS feed ↗5 posts

Latest posts

Form objects in Rails (and why I built HyperActiveForm)

Rails comes with great tools for building forms. When dealing with a single model, everything works smoothly. But as soon as your form needs to touch multiple models, or to have different validations based on context, it can start to get complicated. In this article we’ll look at the standard Rails approach to forms, some of the pain points we’ve all probably encountered, and how form objects ...

Smooth UI animations on server-rendered HTML

I’ve been using Hotwire in production since the beta release of Turbo, and it’s changed the way I build web apps. It’s a great way to get SPA-like interactivity at a fraction of the complexity. In this article, we’ll explore how we can use Turbo 8’s morphing, the view transitions API, and a sprinkle of Stimulus to create a smooth, interactive experience with minimal code. We’ll see how these t...

Launching YAMLFish, a simple translations management tool

As a software engineer, I’ve always dreaded working with translations. It can get increasingly tricky with the number of locales and parallel features being developed. As a CTO of a small company, when updating the YML files manually didn’t cut it anymore, I looked for a simple tool that would help me manage the translations, that would not cost a fortune. I did not find any that suited my ne...

Avoid constantize in Rails

What do you do when you need to instanciate a class in Rails, but its name is dynamic? Let’s say we want to serialize an object for use in an API payload and we have to handle different versions. We could have a MySerializer::V1 and MySerializer::V2 classes. And to instanciate the correct one, we could do something like this: serializer_class = "MySerializer::V#{version}".constantize serial...

Generate magic tokens in Rails with generates_token_for

For a long time, and probably still today, the reference for authentication in Rails is using a gem like Devise. Thing is, you’ll probably end up customizing it a lot: views, emails, onboarding flow, etc. Since Rails 7.1, we have access to several new features that make it easier to implement authentication with minimal extra code, making it a viable option for many projects. One of these fea...