- 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
forQueryLogs
- 12. Facilitate the use of any regular ERB in
database.yml
- 13. Add column information inside ERB templates
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.
On to business.
01. Add drop_enum command for Postgres.
Rails had 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_path
for 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:
config.action_mailer.preview_paths << "#{Rails.root}/lib/mailer_previews"
03. 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.
04. 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:
Prefix Verb URI Pattern Controller#Action
cat GET /cats/:id(.:format) cats#show
PATCH /cats/:id(.:format) cats#update
PUT /cats/:id(.:format) cats#update
DELETE /cats/:id(.:format) cats#destroy
05. 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:
Post.joins(:comments)
.select(
"posts.id as post_id, posts.title as post_title,
comments.id as comment_id, comments.body as comment_body"
)
You can do:
Post.joins(:comments)
.select(
posts: { id: :post_id, title: :post_title },
comments: { id: :comment_id, body: :comment_body}
)
06. Pass options accessor to Cache#fetch
block.
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.
Rails.cache.fetch("3rd-party-token") do |name, options|
token = fetch_token_from_remote
# set the cache's TTL to match the token's TTL
options.expires_in = token.expires_in
token
end
07. Add :locals
to Action View rendering instrumentation.
ActiveSupport::Notifications
will now capture :locals
in addition to :identifier
and :layout
. This change is motivated by the need to gain additional insights into the rendering process to enable developers to make more accurat