By
Nick Flückiger
/14.06.22

Image by Chris Yang

Rails at Renuo

We at Renuo are all crazy about Rails. Or maybe "a bit crazy" because of Rails? 

It is without a doubt our core competence and has been for a long time. Some of us are privately involved in the ruby/rails community and maintain our own set of gems and projects. The best-known of all is definitely cancancan which Alessandro maintains.

As a Rails-Shops at heart, we are interested in the future development of the framework and its continuation in the ever-changing world of software development. Thus we were all very excited when the first release candidate for Rails 7 landed. This is also why we dedicated a big chunk of our learning week to diving into Rails 7.

New Features

Javascript

The biggest change in the Rails 7 update is the new way to manage javascript in your applications. As of Rails 7, you are no longer required to rely on node or webpack for your javascript. A massive change that will undoubtedly save us a lot of time that we would otherwise spend on deciphering those cryptic webpack error messages. Instead, your new Rails application will now come with importamps by default.

Importmaps? Importmaps!

Importmaps are a great way to manage your javascript packages when developing an application with a very simple and small layer of javascript. Instead of installing packages to your machine and importing them from a node_modules folder, you can pin versions directly to a CDN and your browser will fetch the appropriate packages for you. This has been made possible by the improvements made in modern browsers and the general improvement in code distribution on the internet. 

For more complex applications Rails will feature easy integration with esbuild, rollup, and webpack. Our clients will certainly be happy when we can spend even more time on their features as opposed to working on our webpack configuration.

Dynamic/Reactive applications

For some time our applications have harnessed the power of turbolinks and the great improvements of faster navigation and page loads that come with it. We also combined it with some javascript to make the page feel dynamic and responsive. Turbolinks were initially developed for the basecamp application. And now with Rails 7 we are able to use the newest incarnation of the basecamp/hey team! Hotwired -> Stimulus and Turbo. By default Rails 7 will ship with the ultra-light and reactive javascript framework 'Stimulus'. And for extra reactivity and control from the backend, we are able to use 'Turbo'. Turbo is a framework for sending changes from the server to the client. The great and interesting thing about this new tool is that we don't send the data in the form of JSON.. but we send HTML directly over the wire.

This allows developers to seamlessly integrate live DOM updates without having to reload or navigate the page. It builds upon stimulus to deliver an efficient and slim layer of javascript needed for this entire interaction. In most cases, you can get away without writing any javascript! Not only that.. but Turbo will also help you develop stunning applications for IOS and Android. By reusing your Rails code to deliver a hybrid application that has unseen capabilities in code reuse and ease of navigation.

We plan to integrate Turbo in most of the applications where some kind of live updating would be an improvement. We are also planning on using Turbo to deliver the client mobile applications with the great integration into their existing web app.

For upgrading an existing application from Turbolinks to Turbo you probably want to check out the great article written by Alessandro. It was already used multiple times to migrate client projects at Renuo.

Security

Information Technology Companies have the obligation to protect and secure user information so that personal information or critical business information isn't leaked to the public. Hackers will of course try to get around barriers and steal information wherever they can. Encryption and Hashing play a big role in this cat and mouse game. With this iteration of Rails we will be able to encrypt information directly on the database level without much setup. Attribute encryption will be as easy as:

  class User < ApplicationRecord
  encrypts :customer_number
end

We plan to use this feature to improve the security of personal information in a wide range of our projects.

Improvements

Database interactions

In addition to all the new features, we will also receive improvements/updates to existing features.

ActiveRecord::Relation\#excluding

Allowing specifications of excluded entries in a database query.

  Post.excluding(post)

Previously this would have been achieved by excluding the id of the post in question from the result set.

ActiveRecord::Relation\#load_async

A method that allows us to schedule multiple queries in a thread pool and fetch their result as needed. This will make it possible to query multiple values at the same time and thus cut the page load time of some applications. A feature that we are looking forward to.

ActiveRecord::Calculations.calculate

The average aggregation on columns will now respect the column type from the database. This means that there is no longer a dissimilarity between the column type and the return type. This change was implemented by our own Josua Schmid and will come to us in the form of Rails 7.

Deprecations

Sprockets is dead! Long live Propshaft?

Sprockets were the default asset packing mechanism for most rails applications for a very long time. The first commitment to the project was made back in 2008. Since then it has powered a wide range of applications and has served us well... But in the last 14 years, a lot has changed and it is finally time to say goodbye. Rails 7 will no longer ship with the requirement of sprockets. Instead, we are encouraged to use the shiny new Propshaft in its place. An asset delivery tool that was designed with the modern build tools in mind.

The future

All in all, we are very happy with the changes that Rails 7 will bring to us. The changes to javascript are a welcome fresh way of attacking the problem and together with the integration with Turbo we are looking forward to delivering dynamic and versatile applications.

We are looking forward to a great future for Rails and look to rely on Rails for many years to come. We are happy to report that we were able to already migrate some projects to Rails 7 to take advantage of the new updates. One of these projects is Herold, where we hope to use Turbo and Stimulus for a smoother experience and easier-to-maintain code.