This week in Rails: benchmark anywhere, bugfixes and more!

Posted by gregmolnar, December 20, 2020 @ 12:00 am in News

Hi there, it is Greg, bringing you the latest news about Rails!

Rails 6.1 released! Horizontal Sharding, Multi-DB Improvements, Strict Loading, Destroy Associations in Background, Error Objects, and more!

Rails 6.1 has been released and wow does it have a lot of great stuff! The changes include improvements to multiple databases, adding support for destroying associations in jobs instead of in-memory, turning errors into objects, and so much more.

Add benchmark method that can be called from anywhere

This PR includes the existing ActiveSupport::Benchmarkable into the Rails module, to make it accessible from anywhere (background jobs etc).

Add config.action_view.image_loading

Browser native support for lazy loading images is now a part of the official HTML standard and this PR adds Rails.application.config.action_view.image_loading to configure sitewide default for the loading html attribute to enable lazy loading sitewide without changing code.

Add config.action_view.image_decoding

Another image_tag change, which introduces Rails.application.config.action_view.image_decoding to configure the default value of the image_tag :decoding option.

Better handling of negative elements in enum

Rails gives a warning if an enum method uses the not_ prefix as it might conflict with negative scopes. The initial implementation warned even when there was no actual conflict and this change improves that and only warns about negative enums if a positive form that would cause conflicts exists.

Do not use submit_tag auto-disabling when disable_with is set to false

If we have data: { disable_with: false } then auto-disabling is turned off, but if we set automatically_disable_submit_tag to false it changes the behaviour of disable_with in an unexpected way,  so explicit usage of disable_with: false starts to enable auto-disabling with false as the value of a disabled button.
With this change auto-disabling is turned off if we have explicit disable_with: false no matter what is set in automatically_disable_submit_tag.

Ignore strict loading violations on instances loaded through fixtures

Rails 6.1 added _strict_loading_by_default _but that causes issues with the fixtures as they are lazy loaded. To get around it, this change ignores the strict loading flag when the fixtures are loaded.

Fix S3 multipart uploads when threshold is larger than the file uploaded

A bug happened when the file being uploaded to S3 is smaller than the configured multipart threshold, but this PR fixed it.

Allow reload to be default_scoped

reload was not default_scoped by default because you could be creating a record that does not match your default scope and therefore reload wouldn’t find the record. However, in the case of sharding an application you may want reload to
support default_scope because you’ll always have the correct scope
set. 

Change default queue name of all the internal jobs to be the job adapter’s

Before this change you needed to configure your job processor to handle all of Rails’ internal job queues, but not anymore!

Handle nil translation key

In Rails 6.0, the translate helper always returned nil when given a nil key, but in Rails 6.1, the translate helper always raised an I18n::ArgumentError when given a nil key. This PR fixes the translate helper to mirror the I18n.translate behaviour when given a nil key, with and without a default.

45 people contributed to Rails in the past 2 weeks. Check out the open issues if you want to be one if them next time!. Until next week!