Active record improvements and much more

Hi, Wojtek here presenting quite a lot of changes from the past week.

Disable schema dump per database

Dumping the schema is on by default for all databases in an application. To turn it off for a specific database one can now set schema_dump: false in the database config file.

Add change tracking methods for belongs_to associations

Two new methods were added: association_changed? and association_previously_changed? (assuming an association named :association) to Active Record.

Raise error on unpermitted open redirects

Add allow_other_host options to redirect_to. One can opt in to this behaviour with ActionController::Base.raise_on_open_redirects = true.

Update Capybara drivers

Deprecate poltergeist and webkit (capybara-webkit) driver registration for system testing (they will be removed in Rails 7.1) and add cuprite instead.

Fix dirty check for Float::NaN and BigDecimal::NaN

Float::NaN and BigDecimal::NaN in Ruby are special values and can’t be compared with == method.

Make ActiveModel::Errors#inspect slimmer for readability

It will now only output the errors inspection omitting the base object.

Add Middleware#remove

It will raise an error if the middleware is not found.

24 people contributed to Rails since last time. All the changes can be checked here. Until next week!

Performance and parallel testing improvements and more!

Hi, this is Greg, bring you the latest news of the Rails world. It’s been a quiet week, so we don’t have much changes to cover this time.

Fix try and try! performance slowdown in Ruby 2.7+

This PR fixes a performance regression in try and try! under ruby 2.7+.

Fix eager_loading? when ordering with Hash syntax

After this change, eager_loading? is triggered correctly when using order with hash syntax on an outer table, instead of raising an error.

Parallelize tests only when there are enough to justify the parallelization overhead

Parallelizing tests has a cost in terms of database setup and fixture loading. This change makes Rails disable parallelization when the number of tests is below a configurable threshold.

29 people contributed to Rails since last time. All the changes can be checked here. Until next week!

Rails 6.1.4 and plenty of developer UX goodies

Hi, zzak again with the changes from the last week in Rails.

Rails 6.1.4 was released

This release includes many bug fixes so be sure to upgrade! You can read the full summary of changes here.

Deleting an item from the Middleware stack should raise if the item is not found

A bug was fixed when trying to remove a non-existent middleware off the stack.

Generators should raise an error if an attribute has an invalid index

An error is now raised in bin/rails when trying to generate a model with a misspelled “index” attribute.

config_for accepts root shared as an array

A bug was fixed when using config_for with a shared config that is defined as an array.

Handle error when file does not exist at filepath

A more helpful error message is given when using render: file for a non-existent absolute path.

Handle paths with spaces when editing credentials

This issue identifies a bug with trying to use bin/rails credentials:edit on Windows.

Truncate more ActionCable broadcast messages to 300 chars

This PR is a follow-up to an older PR that tried to cut down on ActionCable logging noise in development.

Verify foreign keys after loading fixtures

This PR introduces a new feature where referential integrity is applied to associations when loading fixtures.

It only works for SQLite and Postgres for now, if anyone has idea how to make this work in MySQL.

20 people contributed to Rails since last time. All the changes can be checked here. Until next week!

Perform destroy_all in batches and a lot more features

Hello. News about latest changes in Rails delivered to you by Wojtek.

Active Record destroy_all performs in batches

By default it will load records in batches of 100 and allow to specify the custom batch size.

Add support for ordinal date values

A valid ordinal value will be converted to an instance of TimeWithZone.
In example “21087” value will be parsed to 28-03-2021 date.

Add existence check to foregin key migrations

It is now possible to use if_exists / if_not_exist on remove_foreign_key / add_foreign_key in database migrations.

Add possibility to configure Active Storage for Action Mailbox

It is now possible to configure Active Storage service for storing email raw source via config.action_mailbox.storage_service.

Support strict_loading_by_default in Active Storage

Before the patch, Active Storage representation objects did not play nice with strict loading configuration.

Replace uglifier with terser

Terser is more up to date with modern javascript features, and the uglifier gem repository recommends using it for minifying ES6+ code.

32 people contributed to Rails since last time. All the changes can be checked here. Until next week!

Support preloads on instance dependent associations and more!

Hi there, this is Greg, bringing you the latest changes in Rails!

Time#change should pass the zone property through if it’s set

This PR fixes an issue with changing date objects when the zone is set.

Fix number_to_currency to avoid negative format when displaying zero

This PR fixes number_to_currency to avoid negative format when displaying zero. Before this change, number_to_currency(-0.00456789, precision: 2) _returned _$-0.00

Support preloads on instance dependent associations

From now on instance dependent associations are supporting preloading. To get more details about this change, read the PR descriptions, it explains it really well.

37 people contributed to Rails since last time. All the changes can be checked here. Until next week!

Rails 6.1.4 has been released

Hi everyone,

I am happy to announce that Rails 6.1.4 has been released.

CHANGES since 6.1.3

To view the changes for each gem, please read the changelogs on GitHub:

To see a summary of changes, please read the release on GitHub:

6.1.4 CHANGELOG

Full listing

To see the full list of changes, check out all the commits on GitHub.

SHA-256

If you’d like to verify that your gem is the same as the one I’ve uploaded, please use these SHA-256 hashes.

Here are the checksums for 6.1.4:

$ shasum -a 256 *-6.1.4.gem
2af39c11da8c42f5d529b109e719e82228db15a4d79caccc9165ba0af99b5cf3  actioncable-6.1.4.gem
fe846dbc94c4e4b7eec94cd83e354da4dc2d1511ff40a6271ce27e4849073980  actionmailbox-6.1.4.gem
ee6c7e7a862ad874490c9db3e536c61de07e1b91de698ea6dba52afc78bcb857  actionmailer-6.1.4.gem
8969306876f1406f666bd015ad1e1c8e6622f9ccf6a275b7297f2c13c6ef44de  actionpack-6.1.4.gem
947507251f441261765aa5e8fff36789f6213c9ae454f8cb739436a42842c4ba  actiontext-6.1.4.gem
c44ece3ad757340e80fa53e39e74a5a6b4cae17d6939d7f095b38700cf5f1ecb  actionview-6.1.4.gem
ac14ed1323774f7ddb1cc5f86b75c1169e5ff38e06cc680578155a6b67de0060  activejob-6.1.4.gem
27f3223172e81b8e60e7da7f3b812bba046472716def6793d89c177b9e435e76  activemodel-6.1.4.gem
e0ed04b3da165b2a9f0b2bcf6c664077d4903ac1ce073fdf460ace04933e09a1  activerecord-6.1.4.gem
3c94dc3ba303f6482ea057bfff9393cb0394dc96238d2732eda0feb69734eb0d  activestorage-6.1.4.gem
b37564f4fc3bc66f3f98d3032b8bb8cbdbd23ba0f7c02648287048463cf70f4f  activesupport-6.1.4.gem
b0a266453e4d53beaaf911434f49868fbc6dd3f1e317149e4b160ba6981a6d4c  rails-6.1.4.gem
a456517e6861aff2b58711bf95a20ec2ec9434ba921aacd776e3c23b39069743  railties-6.1.4.gem

As always, huge thanks to the many contributors who helped with this release.

Rails 6.0.4, Lots of Active Storage goodies, and many Quality-of-Life improvements!

Hello, zzak here with the latest changes from the last week to Rails.

Rails 6.0.4 was released

This release includes many bug fixes so be sure to upgrade! You can read the full summary of changes here.

Improve security of untyped bound values in MySQL

This solves a potential query manipulation vulnerability with MySQL.

Improve usability of multi-db when config is invalid

A helpful exception is now raised if pool_config is nil when using config.active_record.writing_role(:all).

Enhancements to Active Record Encryption

After introducing encryption into Active Record, a couple new features and a bug fix were followed!

Add support for eager loading Active Storage variants

This PR removes N+1 queries from Active Storage when using with_all_variant_records and with_attached_* scope.

Fix strict loading through associations

Previously there was a bug when using strict_loading where eager loading wouldn’t propagate through associations.

Use the current Rails version inside package.json

Previously when generating a new Rails app, the package.json would hard-code the string “6.0.0” for all npm dependencies. This now uses the Rails version that generated the app.

Add support for Active Storage expiring URLs

This allows expiring URLs for signed blob ids in Active Storage via the “expires_in” parameter or by setting a default with “config.active_storage.urls_expire_in”.

Support default “cache_control” in Active Storage for GCS

This PR adds support for setting the default “cache_control” headers for uploads using Google Cloud Storage service.

Use FFmpeg scene detection for generating video previews

By using the built-in features of FFmpeg, Active Storage now generates much better thumbnails for videos. These parameters were also made configurable in a follow-up PR!

Deprecate “purge” and “purge_later” on Active Storage attachments association model

You should be calling these methods directly on the attachment and not on the association.

Add Model.update! that is similar to Model.update but raises exceptions

You may be familiar with the instance method Model#update!, but now you can do that on the class!

Performance regression in CollectionAssocation#build

This fixes a huge performance bug for inversing associations with a lot of records.

Reduce stat(2) calls

Classic nobu. This patch was later optimized in a follow-up PR.

Don’t attach UJS form submission handlers to Turbo forms

This quality-of-life improvement is for apps migrating from RailsUJS to Turbo with both living inside the codebase to easily distinguish which should handle forms.

28 people contributed to Rails since last time. All the changes can be checked here. Until next week!

Rails 6.0.4 has been released

Hi everyone,

I am happy to announce that Rails 6.0.4 has been released.

CHANGES since 6.0.3

To view the changes for each gem, please read the changelogs on GitHub:

To see a summary of changes, please read the release on GitHub:

6.0.4 CHANGELOG

Full listing

To see the full list of changes, check out all the commits on GitHub.

SHA-256

If you’d like to verify that your gem is the same as the one I’ve uploaded, please use these SHA-256 hashes.

Here are the checksums for 6.0.4:

$ shasum -a 256 *-6.0.4.gem
384a4edf491b5a77d81cd4e39f9e7ccc1d758178a342df5a874a0d3694bef21a  actioncable-6.0.4.gem
a9bbbe0ef49cbbb5c88bd2bd9c76afb56e4204d958eaea7482393acf8a4f4263  actionmailbox-6.0.4.gem
5eee44456af0201339787aab249f946cdb65fb0a042164ddd7889206de80f716  actionmailer-6.0.4.gem
815b66107fca6f872a7fe1badd9d7fb5dabc20634b538b35bce828b981845372  actionpack-6.0.4.gem
88eddd0d4be7650d374eecb14e8bb409776ee86e775c1a14f9db7477c9c3562b  actiontext-6.0.4.gem
433f05773ac40f4f8b8df5fdcd6bc83701b262963b097759eb6d8a9367dbe89b  actionview-6.0.4.gem
648ad0e611171b969572ff2cb898f43bbd6887daf532d49bab5f3d0edc573f3f  activejob-6.0.4.gem
e61b2e6f2c167c64bd9eb1db35b97ae8c724fabf8604e5e3d7456c1e87760de9  activemodel-6.0.4.gem
8dcf08a6c780cc4f34140c624c2f4adfc96e6a6b9538c94db16e221d62976958  activerecord-6.0.4.gem
d18793d1b42d80e49b3c2e4772624c9b61a066ad841c21fa4f6046eac002fdee  activestorage-6.0.4.gem
ddc14fc858d8a3ac8b22fa612c74d96f6ca5bea91aab1969b579b7b5d2b6f25e  activesupport-6.0.4.gem
4fcf7ceeae044e95be52efd5a3f94ec14872643121a461187424246fdd0df7cb  rails-6.0.4.gem
c5bf0d0a9e78f5481e1b96ead3450d0888aa01fd8b55be07f55d7237eaca2792  railties-6.0.4.gem

As always, huge thanks to the many contributors who helped with this release.

Active Storage audio improvements and more

Hi, Wojtek here with the summary of changes from the last week.

Add audio analyzer to Active Storage

It extracts duration and bit rate of audio files and stores it in the record metadata column.

Recognize audio presence in the video blobs

The metadata attribute of video blobs has a new boolean key named audio that is set to true if the file has an audio channel and false if it doesn’t.

Add attributes_for_database to Active Record

Returns attributes with values for assignment to the database. It works both for Active Record and Active Model objects.

Get rid of cattr_accessor in ActiveRecord::Base

More work on improving performance by eliminating class variables. This is a followup to previous change where detailed benchmark can be found.

23 people contributed to Rails since last time. All the changes can be checked here. Until next week!

Active Record Encrytion, several performance optimizations, and much MORE!

Hi, zzak here! お久しぶりです! This time I will be recapping the past month or so of Rails. Hang on! There’s a ton of stuff to catch up on!!

Active Record Encryption

Originally extracted from HEY, this feature adds encrypted attributes to Active Record models. You can find out more in the guide.

Optimize Cache::Entry coder

Active Support’s cache has received a significant speed bump that was well overdue.

Optimize Active Model generated attribute methods

This optimization should reduce memory overhead and speed up boot times.

7x speed up for ActiveRecord::Base.logger

By converting AR::Base.logger to a class_attribute we had significant performance gains.

Allow nesting locales for Engines

This opens up better organization for larger apps using i18n. e.g. config/locales/en/models.yml vs. config/locales/models.en.yml

Support Range objects in Active Job

This change adds an Active Job serializer for the Range object from Ruby.

Add Enumerable#sole to Active Support

Based on ActiveRecord::FinderMethods#sole, this method returns the sole item of the enumerable. If there are no items, or more than one item it will raise an exception.

Deprecate Enumerable#sum and Array#sum

Since Ruby 2.4 included these methods, Rails can start using the native versions for significant performance increase.

Improve Active Record performance for #one? and #many?

By limiting the generated count queries, this optimization provides significant performance increase for operations over many rows.

Log a warning when running SQLite in production

A warning is now emitted when trying to use SQLite in production, this can be disabled by setting config.active_record.sqlite3_production_warning to false.

Add disable_joins option to has_one relation

This solves a problem with has_one…through relationships whose tables are in separate database clusters.

Add support for require-trusted-types-for and trusted-types

This feature adds support for these two Content-Security-Policy headers which you can read more about over at MDN.

Remove and deprecate Rack::Runtime

Any apps depending on this middleware can still activate it manually, otherwise a deprecation warning will be sent and replaced with a fake.

Allow access to nested secrets in Rails.application.credentials

Now Rails.application.credentials.aws.access_key_id will return the same thing as Rails.application.credentials.aws[:access_key_id].

Add ActionController::Live#send_stream

Adds the ability to live stream binary data to the browser like send_data does for static files.

Extract ActiveStorage::Streaming

This allows you to stream blobs from cloud storage in any controller.

Add from: option to ActiveSupport::TestCase#assert_no_changes

This feature provides an optional keyword argument to assert_no_changes to specify the expected initial value.

61 people contributed to Rails this month. Check out the open issues to get involved and help out. Until next week!