Ruby on Rails - December 2023
The last edition of 2023 - The only Ruby on Rails newsletter you will ever need!
Greetings,
Welcome to this month's edition of the "Ruby on Rails, Monthly" newsletter! As always, I'm Sajjad Umar, your very own DesiDeveloper, here to keep you abreast of the latest happenings in the world of Ruby on Rails. From updates in frameworks to the newest gems and best practices, I've got you covered.
As we approach the holiday season—wherever you are in the world—let's take a moment to celebrate the joys and festivities this time brings. It's a season of reflection and gratitude, and I hope it's filled with warmth and cheer for you and your loved ones.
I'm thrilled to share some fantastic news from my Desi Developer YouTube channel this holiday season! I've launched an incredible Giveaway Series aimed at enhancing productivity for developers and creators. Don't miss out on the chance to win some incredible tools in my latest video titled "Essential YouTube Creator Gear Giveaway | Win Your Content Creation Toolkit!"
Also, as we near the end of this year, I want to express my gratitude for your continued support. This edition marks the last of "Ruby on Rails, Monthly" for this year, and I'm eagerly looking forward to what the next year holds. There's a lot in store, with exciting updates, insightful content, and more giveaways coming your way in the new year!
With that being said; let’s jump right into the updates:
The official Rails job board is live
Great news for job seekers and employers within the Ruby on Rails community! The newly launched official Rails job board is now live, providing developers with job opportunities while enabling companies to post job openings. This initiative by RailsWorld is a fantastic step forward for the community.
Read all the details here.
Shopify CEO Tobi Lutke shared impressive stats about the scalability of Rails
Some say Rails does not scale well, but Sopify stats suggest otherwise as Ruby on Rails at Shopify is handling ~60 million requests per minute, YES you read that right it’s million and minute with “m”. That’s impressive!
See the original post and the discussion here.
Let's explore some thrilling updates within the Rails codebase!
TransformJob
Update for Non-Image Files
Resolved an issue in ActiveStorage's TransformJob
related to non-image files like PDFs causing failures with ActiveStorage::InvariableError
. This fix allowed identification and proper generation of previews for such files, ensuring smoother processing.
Read all the details here.
Delayed Validation of Registered Active Record Adapters and Adapter Aliasing
This change allows for the delayed validation of Active Record adapters and the capability to alias adapters by name. This long-term aim is to map mysql
to either trilogy
or mysql2
at the application level.
Read all the details here.
Fixed an issue in ActiveStorage::Representations::ProxyController
When a blob is a representable
of kind previewable
, the preview image that's being proxied is always the original preview image, discarding completely the variation_key param passed in the request.
This PR fixes this by editing Preview
and VariantWithRecord
to have full synchronized API with Variant
. this then allows the ProxyController
to not call representable#image
but representable
instead.
Read all the details here.
Fixed word_wrap
with Empty String:
Addressed an issue where word_wrap
previously returned nil
when given an empty string. It now correctly provides an empty string, ensuring smoother handling.
Read all the details here.
Incorporated ActiveRecord
Suffixes into ActiveStorage
Database Models
This Pull Request has been created because ActiveStorage db model table names are hardcoded. Making it impossible to be compatible with ActiveRecord
prefix/suffix configuration.
What's also problematic is that ActiveStorage
generated migrations ( with activestorage:install
task ) respects the prefix/suffix configuration, which makes it impossible to use ActiveStorage models in a Rails application.
To fix this issue we removed the hard-coded lines. But then we must also override an internal method for specifying the prefix.
Read all the details here.
Introduced Action Mailer Bug Report Template
Introduced bug report templates within Action Mailer, aiding contributors in replicating and reporting issues with failing ActionMailer::TestCase
instances, streamlining the resolution process.
Read all the details here.
Supported nested elements inside button tag in Active Storage uploads
This update resolves a potential issue encountered when nested elements, such as spans or icons, were present within a button or a submit-type input during Active Storage uploads.
Read all the details here.
Elimination of Deprecated Features
This ongoing PR is part of the effort to remove deprecated code, previously marked as obsolete for Rails 7.2. Explore the PR to understand what features are being phased out and if you are already handling them.
Read all the details here.
Preserved serialized timezone when deserializing with ActiveJob::Serializers::TimeWithZoneSerializer
This Pull Request changes ActiveJob::Serializers::TimeWithZoneSerializer
to include the time zone of the provided time_with_zone
object in the serialized hash which is then used during deserialization.
Read all the details here.
Enhanced ActiveStorage::Preview
Processing
Upgraded ActiveStorage's Preview
feature to simultaneously generate both the full-sized preview image and the requested variant during processing. For example, using attached_pdf.preview(:thumb).processed
promptly creates both the full-sized and the :thumb
variant of the image.
Read all the details here.
Improved Handling of MySQL
Warnings in ActiveRecord.db_warnings_action
This enhancement addresses situations in MySQL where warning_count
was greater than zero but no warnings were returned with the SHOW WARNINGS
query. The fix ensures ActiveRecord.db_warnings_action
proc is triggered with a generic warning message instead of ignoring the warnings silently.
Read all the details here.
ErrorReporter#unexpected
reported in production but raised in development
It's a common useful pattern for situations where something isn't supposed to happen, but if it does we can recover from it.
So in such a situation, you don't want such an issue to be hidden in development or test, as it's likely a bug, but do not want to fail a request if it happens in production.
In other words, it behaves like #record
in development
and test environments
, and like raise
in production
.
Read all the details here.
Aliased field_set_tag
helper to fieldset_tag
The field_set_tag
renders a <fieldset>
element. At times, the desire to render a fieldset results in calling the fieldset_tag
, only to be surprised by a NoMethodError
.
Originally, the method's name was fieldset_tag
but it was renamed 3 days later.
This commit aliases field_set_tag
to fieldset_tag
so that both are available.
Read all the details here.
with_routing test helper now works for integration tests
This Pull Request changes routing assertions in integration tests by including ActionDispatch::Assertions::RoutingAssertions::WithIntegrationRouting
which overrides the standard with_routing
machinery to mutate the app under test and integration session.
Read all the details here.
Made isolated engines aware of ActiveRecord::Base
table name prefix
This Pull Request redefines table_name_prefix
for engines only when ActiveRecord
is loaded, this will allow to prepend ActiveRecord::Base.table_name_prefix
for isolated engines that generate ActiveRecord
tables for their internal use.
Read all the details here.
Standardized Return Values in Cache::Store#write
Standardized the return value of Cache::Store#write
across various backends, distinguishing between successful writes, communication errors with the backend, and other failure reasons for improved clarity.
The return value of Cache::Store#write
was not specified before, and varied between backends. This PR makes it consistent:
true
indicates a successful writenil
indicates an error talking to the cache backendfalse
indicates a write that failed for another reason
Read all the details here.
Added ActiveRecord.protocol_adapters
configuration to map DATABASE_URL
protocols
When configuring a database connection using DATABASE_URL
, defining the adapter within the deployment environment config becomes necessary. However, the concern primarily lies with the DBMS/protocol rather than specifying an adapter class. For instance, it's more about stating "this Rails app connects to MySQL" rather than specifying the connection using a particular adapter class.
This adjustment proves significant, especially when transitioning between mysql2 and trilogy, both being primary DB adapters for connecting to MySQL. This concern extends beyond just custom adapters and likely applies to upcoming adapters as well.
The proposed solution involved incorporating an Active Record configuration to map protocols to adapters within database URLs. This configuration, introduced in ActiveRecord::DatabaseConfigurations::UrlConfig
(handled internally by ActiveRecord::DatabaseConfigurations::ConnectionUrlResolver
class), allows mapping from protocol to adapter, offering flexibility in defining connections without directly modifying the environment.
Read all the details here.
Allowed object_id
as a column name for ActiveRecord
This Pull Request removes the object_id
from the list of not-allowed column names.
For the sake of consistency, the comments and tests are updated where relevant to use the __id__
method instead.
Read all the details here.
Fixed Time.now/DateTime.now/Date.today
to return results in a system timezone after #travel_to
There was a bug in the current implementation of #travel_to
: it remembers a timezone of its argument, and all stubbed methods (Time.now, DateTime.now, Date.today
) start returning results in that remembered timezone. However, the expected behavior is to return results in a system timezone. This PR has fixed this issue.
Read all the details here.
Participate in Giveaway, or Sponsor it!
That's a wrap for this month's edition of Ruby on Rails Monthly! Wishing you all a joyful and prosperous New Year as we approach the celebrations.
Until we meet again ✌🏻
A secret message at the end for all paid subscribers 👇
Keep reading with a 7-day free trial
Subscribe to Ruby on Rails - Monthly to keep reading this post and get 7 days of free access to the full post archives.