- 01. Add drop_enum command for Postgres.
- 02. Support multiple preview paths for mailers.
- 03. error_highlight gem to locate columns with errors.
- 04. routes --grep to filter routes by paths.
- 05. ActiveRecord::QueryMethods#select accepts a hash.
- 06. Pass options accessor to Cache#fetch block.
- 07. Add :locals to Action View rendering instrumentation.
- 08. Rails.error.report now marks errors as reported.
- 09. ActionController::Parameters#exclude? added.
- 10. Allow passing classes to dom_id.
- 11. Add the ability to set the tags_format for QueryLogs.
- 12. Facilitate the use of any regular ERB in database.yml.
- 13. Add column information inside ERB templates.
Here are links to the other parts of the series:
- An Overview Of Ruby on Rails 7.1 Features. Part I
- An Overview Of Ruby on Rails 7.1 Features. Part III
If you landed here through a search engine or a referral link, this is the second part of a three-part blog post series of features coming to Rails 7.1. Please see the intro section of An Overview Of Rails 7.1 Features. Part I for some context.
I encourage you to scroll down and subscribe to my newsletter for Ruby and Rails goodies if you’d like to stay up to date on developments or tips.
01. Add drop_enum command for Postgres.
create_enum for Postgres without a matching
drop_enum. This pull request added
drop_enum while another pull request made
drop_enum reversible. The latter pull request made it possible so that if the
if_exists: true option is provided, the enum is dropped only if it exists. Otherwise, if the enum doesn’t exist, an
ActiveRecord::IrreversibleMigration error is raised.
02. Support multiple preview paths for mailers.
The changes in this pull request make it possible to preview emails from engines, it does so by deprecating
config.action_mailer.preview_paths where one can add locations for mailer previews for Rails to search, so instead of having a single search path set, you can append multiple search paths:
error_highlight gem to locate columns with errors.
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.
routes --grep to filter routes by paths.
Rails will extend
bin/rails routes --grep to match paths too. So if you run
$ bin/rails routes -g /cats/1, you can expect to get:
ActiveRecord::QueryMethods#select accepts a hash.
If you prefer hashes over raw SQL strings, now you can use them with select when you join tables. For instance instead of:
You can do:
06. Pass options accessor to
With this change, it is possible to pass cache options to the fetch method, so if you use third party auth tokens and store them in the cache, you can set the cache expiry time to the same as the expiry time of the token, so the cache can expire along with the TTL of these third party tokens.
:locals to Action View rendering instrumentation.
ActiveSupport::Notifications will now capture
:locals in addition to
:layout. This change is motivated by the need to gain additional insights into the rendering process to enable developers to make more accurate assertions about it during testing. Additionally, it may also be useful for APM purposes.
Rails.error.report now marks errors as reported.
This is more of a bug fix maybe. Either way, still a great merge in my books. The
Rails.error.report method has been updated to mark reported errors as such, to prevent them from being reported multiple times. This is useful in cases where users want to report errors with additional context before allowing them to bubble up, or where errors need to be safely caught and reported outside of the execution context.
Adding this method keeps things a little more consistent with a Hash. Rails already provides
ActionController::Parameters#exclude? is only natural. The new
exclude? method returns
true if the given key is not present in the parameters. It’s the inverse of
10. Allow passing classes to
You can now pass a class directly to
dom_id without having to call
new. This makes using
dom_id more similar to using
dom_class, and it also helps to improve performance by avoiding the creation of a new object just to generate a string. This can save a few keystrokes and improve the efficiency of your code.
11. Add the ability to set the
This pull request introduces a new option called
tags_format option allows users to customize the separator and quoting style used for key-value pairs in their query logs. By default,
tags_format uses a colon (:) as the separator and does not add quotes around values. However, some users may prefer to use a different separator, such as an equals sign (=) as used by the
sqlcommenter gem. The
tags_format option allows users to choose between the default behaviour and the
:sqlcommenter style by setting the option to the corresponding symbol.
12. Facilitate the use of any regular ERB in
DummyCompiler has been replaced with
ERB::Compiler. True to what dummy compilers do, it’d blow up when one tried to use ERB in a YAML key. This pull request makes it possible to use ERB in YAML keys. While at it, Rails also deprecated
So we can now do stuff like:
13. Add column information inside ERB templates.
That’s it for this instalment! Part III is in the works with about 25 features. What has been your favourite feature so far? You can let me know in the comments.