This Week in Rails

December 30, 2022

This Year in Rails, a summary of 2022!

Hey!

This is Emmanuel, Greg and Wojciech, bringing you the summary of what happened with Rails in the past year. It was a busy year with 3131 commits from 491 contributors and 31 releases!

We carefully selected the most significant pull requests for inclusion, but it is possible that we may have overlooked some due to the need to keep the newsletter concise. That said, Emmanuel is compiling a comprehensive list of pull requests for Rails this year.

Introducing: The Rails Foundation
In case you missed it, with eight founding members, Rails has started The Rails Foundation! Together, the founding members have contributed a total sum of $1,000,000 that will aid the foundation's mission to improve the documentation, education, marketing, and events in our ecosystem. More here.

Stimulus gets an Outlets API
Around Hotwire, this pull request received a warm welcome. I reached out to the author, Marco Roth, who whipped out a documentation that perfectly summarises the Outlet API:

Allow setting YAML serialization options on a per-attribute basis
This pull request adds functionality to allow setting YAML serialization options on a per-attribute basis - along with the current application-wide setting.

Docked Rails CLI
Setting up Rails for the first time with all the dependencies necessary can be daunting for beginners. Docked Rails CLI uses a Docker image to make it much easier, requiring only Docker to be installed.

Add default Dockerfiles
This pull request adds Docker files by default to new apps: Dockerfile, .dockerignore, bin/docker-entrypoint. These files can be skipped with --skip-docker. They're intended as a starting point for a production deploy of the application. Not intended for development (use the above mentioned Docked Rails for that). You can see more details about using it on the pull request.

Use the error_highlight gem to locate the columns where an error was raised
Ruby 3.1 added the error_highlight gem to display the fine-grained location of where an error occurred. Rails will now use error_highlight on error pages to show the column range of where an error occurred.

Support password challenge via has_secure_password
This allows a password challenge to be implemented with the same ease as a password confirmation, re-using the same error handling logic in the view, as well as the controller.

Auto-create user and grant privileges when creating mysql databases
Creating the database user and granting privileges every time you need to set up Rails locally on a new computer can be tedious. This change adds it to the MySQL build rake task, using the root user with no password.

Stop autoclosing of PRs
While the idea of cleaning up the pull request list by nudging reviewers with the stale message and closing pull requests that didn't got a review in time could work for the maintainers, in practice it discourages contributors to submit contributions.

Add --name option to the app generator
The option --name will override the application name to be different from the folder name.

Previously, when saving a record, Active Record would perform an extra query to check for the uniqueness of each attribute having a uniqueness validation, even if that attribute hadn't changed.
If the database has the corresponding unique index, then this validation can never fail for persisted records, and we can safely skip it.

Allow opting out of the SameSite cookie
You can now opt out of using SameSite on your cookies by passing same_site: nil.

Common Table Expression support added "out-of-the-box
You can now build sophisticated queries with Common Table Expressions using the .with query method on models. The .with method allows the usage of Active Record relations without the need to manually build Arel::Nodes::As nodes.

Allow passing Hash on secure password validations

You can now pass an option hash to _has_secure_password, with :if / :unless / :on keys, to control when should the validations be executed.

Add drop_enum migration command for PostgreSQL

This does the inverse of create_enum. Before dropping an enum, ensure you have dropped columns that depend on it.

Add ActiveRecord::Base::normalizes
This method can be used to declare normalizations for attribute values. Normalizations are applied when attributes are assigned or updated, and the normalized values will be persisted to the database. Normalizations are also applied to matching keyword arguments of finder methods. This allows a record to be created and later queried using an un-normalized value.

That's a wrap! Have a great New Year's Eve and see you next year!

About This Week in Rails

Your weekly inside scoop of interesting commits, pull requests and more from Rails.