Hi! Emmanuel Hayford here with some Rails codebase updates for you!
Add #assert_events_reported test helper
Rails added a new test helper that lets you assert multiple events were reported within a block— order-agnostic , with support for payload and tag matching, and it ignores extra events. Handy for workflows that emit several instrumentation events in one go.
assert_events_reported([
{ name: "user.created", payload: { id: 123 } },
{ name: "email.sent", payload: { to: "user@example.com" } }
]) do
create_user_and_send_welcome_email
end
Add deliver_all_later
to enqueue multiple emails at once
You can now enqueue many emails in one go—reducing round trips to your queue backend. Build an array of MessageDelivery objects and push them at once. Options (like queue: ) are forwarded to the jobs. Under the hood this uses ActiveJob.perform_all_later , and if the adapter doesn’t support bulk enqueue it gracefully falls back to enqueuing individually.
# Build deliveries
user_emails = User.find_each.map { |user| Notifier.welcome(user) }
# Enqueue all at once
ActionMailer.deliver_all_later(user_emails)
Add Copy as Text button to error pages
“Copy as text” button on error pages — Development error pages now include a Copy as text button in the header that puts a concise, plain‑text version of the exception on your clipboard.
Remove autocomplete=”off” from hidden inputs in button_to
Hidden inputs generated by form_tag , token_tag , method_tag , and the hidden params inside button_to no longer force autocomplete=”off”. A new setting, config.action_view.remove_hidden_field_autocomplete , controls this behaviour (default stays false for existing apps; load_defaults 8.1 sets it to true )
Rails.application.config.action_view.remove_hidden_field_autocomplete = true
Structured Event Reporting in Rails
Rails adds a first‑class Event Reporter with a unified API for structured telemetry. Access it via Rails.event and emit events with context and tags:
Rails.event.set_context(request_id: "abc123", shop_id: 456)
Rails.event.tagged("graphql") do
Rails.event.notify("user.signup", user_id: 123, email: "user@example.com")
end
Applications subscribe to events and choose an encoder (e.g., JSON) for output:
class MySubscriber
def emit(event)
encoded = ActiveSupport::EventReporter.encoder(:json).encode(event)
StructuredLogExporter.export(encoded)
end
end
Rails.event.subscribe(MySubscriber.new)
Action Cable: stream_for now supports composite channels
You can now stream and broadcast to composite targets by passing an array to ActionCable::Channel#stream_for / # broadcast_to , similar to Turbo’s composite broadcasting. This lets you scope a stream to multiple models at once:
class ChatChannel < ApplicationCable::Channel
def subscribed
stream_for [room, current_user] # composite target
end
end
Share rate limits across controllers with scope:
You can now share a single rate‑limit counter across multiple controllers by passing a scope: to rate_limit. By default, limits are scoped per controller, but using the same scope value lets different controllers share the same bucket.
You can view the whole list of changes here.
We had 35 contributors to the Rails codebase this past week!
Until next time!
Subscribe to get these updates mailed to you.
Your weekly inside scoop of interesting commits, pull requests and more from Rails.
Subscribe to get these updates mailed to you.