Ruby on Rails - January 2024
Sajjad Umar
Senior Backend Engineer | Ruby on Rails | Author of Ruby on Rails for Agile Web Development | Manager RubyConfPk | Desi Developer | Building adex.world
Greetings,
Happy New Year! Welcome to the first edition of the "Ruby on Rails, Monthly" newsletter for 2024! I hope your January is off to a fantastic start, filled with renewed energy and enthusiasm for all the possibilities this year holds. I'm Sajjad Umar, your DesiDeveloper, and I'm thrilled to embark on another year of keeping you informed about the latest developments in the dynamic world of Ruby on Rails.
Let's dive right in.
Rails World
Mark your calendars for the upcoming Rails World event scheduled for September 26th and 27th, 2024, in Toronto, Canada.
Rails World has announced the venue, the sponsorship options, information about the CFP, and the ticket costs for the next Rails World conference.
Read all the details here.
Ruby 3.3.0 Released
Ruby 3.3.0 has been released. Ruby 3.3 adds a new parser named Prism, uses Lrama as a parser generator, adds a new pure-Ruby JIT compiler named RJIT, and many performance improvements especially YJIT.
Read all the details here.
What's Ahead? Rails 8 Milestones
DHH created a milestone for Rails 8 and in my opinion, some of the goals are:
Read all the details about these goals and more here.
Now let’s have a look at what has changed in the rails codebase in last 30 days:
Added webp and avif as allowed formats for active storage to serve inline
ActiveStorage now supports webp and avif formats for active_storage.content_types_allowed_inline.
Read all the details here.
Fixed inclusion of url_helpers module in concern
The dynamically generated url_helpers module is an ActiveSupport::Concern. Therefore, when it is included directly in another ActiveSupport::Concern, its included block is deferred until the latter concern is itself included elsewhere. Thus, in that case, the call to base._routes in def self.included(base) will raise NoMethodError because the included block will not yet have defined the _routes method.
This commit prevents the error by first checking if base responds to _routes.
Read all the details here.
Added ActionView bug report template
This PR Introduces Action View bug report templates for contributors to reproduce issues with failing ActionView::TestCase instances.
In addition to rendering ERB with the inline: keyword, the sample tests also include a Helpers module to demonstrate how to incorporate view helpers into the reproduction script.
Read all the details here.
Do not generate pidfile in production environments
This Pull Request has been created to not create pidfiles in production.
This makes the pidfile instruction from the default puma.tt template conditional. The puma files in the respective dummy / test apps have been updated for consistency. The default path for the pidfile in the server command has also been made conditional.
Read all the details here.
Consolidated bug_report_templates and removed the gem versions
Before this modification, the Rails repository maintained two sets of bug report templates, differing only in the Rails version they utilized. With this adjustment, a single line change has consolidated them into a unified template moving forward.
Read all the details here.
Expose assert_queries and assert_no_queries assertions
To assert the expected number of queries are made, Rails internally uses assert_queries and assert_no_queries. These assertions can now be used in applications as well.
Read all the details here.
Exposed assert_queries_match and assert_no_queries_match assertions
The initially introduced helpers have certain limitations. For instance:
While these limitations generally suffice for regular users, they can be restrictive when attempting to test more intricate behaviors, such as within a gem's tests. A notable example is the inability to test the creation of an index and a foreign key during the execution of a specific operation.
Now, this can be achieved with the following code:
assert_queries_match(/create index/i, include_schema: true) do
do_something
end
Read all the details here.
Added instrumentation for ActionController::Live#send_stream
This PR adds instrumentation for ActionController::Live#send_stream. The event payload contains the filename, disposition, and type.
Read all the details here.
Allowed serving compressed SVG images
This PR adds image/svg+xml to the compressible content types of ActionDispatch::Static.
Read all the details here.
Added default pwa manifest and service worker file
Having the PWA manifest and service-worker.js files under app/views/pwa means we can work on them dynamically with ERB and other techniques. They're mounted via a built-in Rails controller and explicitly revealed in the routes.rb file to ensure there are no surprises. This PR adds it.
Read all the details here.
TrilogyAdapter: ignore host if socket is set
Contrary to mysql2, trilogy will ignore the socket config if host is set.
This makes it impossible to configure a UNIX domain socket connection via DATABASE_URL, as the URL must include a host. This PR allows to configure a connection on a UNIX socket via DATABASE_URL.
Read all the details here.
Added support for generated columns in SQLite3 adapter
SQLite is a feature-rich database engine, and production usage is only growing. We need Rails' support to offer developers the range and scope of its features.
Both the MySQL and PostgreSQL adapters support virtual columns, and SQLite itself has support generated columns since 2020.
PR #41856 introduced virtual columns to the PostgreSQLAdapter. This is effectively a clone of that feature, with some necessary tweaks.
Read all the details here.
Arel nulls first/last implementation Mysql
This Pull Request changes the implementation of .nulls_first() and .nulls_last() for MySQL databases. These methods now work as designed.
Read all the details here.
领英推荐
Added runner script option to disable Executor wrap
This Pull Request allows passing --skip-executor to the Rails script runner to conditionally not add an Executor wrap to the script.
Read all the details here.
AR Affixes
Take AR affixes into account for Action Mailbox and Action Text database models
This removes the redundant hard coded table names to make the models compatible with ActiveRecord::Base.{prefix|suffix}.
This also adds prefix/suffix in the dummy app to force the entire test suite to be agnostic to hard-coded table names.
Rails UJS has been deprecated since Rails 7, time to die
We will still have the official package at @rails/ujs and also leave the final compiled targets for the asset pipeline. But everything else ought to go.
Read all the details here.
Added rate limiting to ActionController via the Kredis limiter type
Added rate limiting API using Redis and the Kredis limiter type.
class SessionsController < ApplicationController
rate_limit to: 10, within: 3.minutes, only: :create
end
class SignupsController < ApplicationController
rate_limit to: 1000, within: 10.seconds,
by: -> { request.domain }, with: -> { redirect_to busy_controller_url, alert: "Too many signups!" }, only: :new
end
Read all the details here.
Added rubocop-rails-omakase to new Rails applications
This setups a basic rubocop config for new rails apps using the rubocop-rails-omakase gem.
It can be skipped with the --skip-rubocop flag.
Read all the details here.
Bumped the required Ruby version to 3.1.0
As Ruby 3.0 will reach EOL in march, this PR bumps the required Ruby version to 3.1.0.
Read all the details here.
Added allow_browser to set minimum versions for your application
This PR makes it easy to specify which browsers you’ve supported to allow access to your application.
Read all the details here.
Added Brakeman by default to new apps
This PR makes changes to add Brakeman by default to all new apps
It can be skipped with the --skip-brakeman flag.
Read all the details here.
Rails now create GitHub CI files by Default
Now that we have rubocop and brakeman by default, it makes sense to add a default GitHub CI workflow file for new applications. This will get especially newcomers off to a good start with automated scanning, linting, and testing. That's a natural continuation for the modern age of what we've done since the start with unit tests.
So this PR makes it to add .github/workflows/ci.yml and .github/dependabot.yml with good defaults. This can be avoided with --skip-ci.
Read all the details here.
Updated the default Puma configuration
Currently the default Puma thread count to 5. That's very high. This PR changes it to 3.
Read all the details here.
Yield instance to Object#with block
The introduction of the block argument means that Object#with can now accept a Symbol#to_proc as the block argument:
client.with(timeout: 5_000, &:ping)
This PR makes it possible.
Read all the details here.
Prevents unnecessary application reloads in development
This PR fixes this issue by ensuring the application reloads correctly according to Rails.autoloaders.main.dirs, thereby preventing unnecessary reloads.
Read all the details here.
Added oven-sh/setup-bun to GitHub CI when generating an app with bun
When generating an app with bun, GitHub CI test fails with Command install failed, ensure bun is installed.
This Pull Request adds oven-sh/setup-bun to ci.yml when generating an app with bun.
Read all the details here.
Added explain support for methods like last, pluck and count
Currently explain doesn't work for queries using last, pluck or count, as these return the actual result instead of a relation. This makes it difficult to optimize these queries.
This PR adds explain support for these methods.
Read all the details here.
Added support for :on option in #set_callback
This PR Introduces ActiveRecord::Transactions::ClassMethods#set_callback which behaves like ActiveSupport::Callbacks::ClassMethods#set_callback with support for the :on option available on #after_commit and #after_rollback callbacks.
Read all the details here.
Added default: support for ActiveSupport::CurrentAttributes.attribute
This PR extends the .attribute class method to accept a :default option for its list of attributes:
class Current < ActiveSupport::CurrentAttributes
attribute :counter, default: 0
end
Read all the details here.
Desi Developer
Yours truly is building a community-powered cross-promotion platform called Adex, and I’m glad that quite a few people are showing interest in the idea.
If you are interested to know more about the project consider subscribing to the waiting list at https://adex.world.
And that is it for this month’s Ruby on Rails Monthly, will be back with more updates next month ??
Thanks for supporting this newsletter!
Hey there! Great to see the January 2024 edition of Ruby on Rails Monthly go live! At ManyMangoes, we totally get the importance of having a solid team behind every project. Speaking of teams, we've been finding our rockstar sales staff through CloudTask! They've got a treasure trove of vetted sales professionals you can browse with videos. Definitely worth checking out for your team too! Here's where you can find them: https://cloudtask.grsm.io/top-sales-talent ??
Join Forces with ??? Blackwall: Leading the Charge in Security as a Service (SECaaS) for Cloud Providers and Hosters ??
1 年Great contribution Sajjad Umar !