惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
博客园 - 司徒正美
小众软件
小众软件
H
Help Net Security
博客园 - 聂微东
宝玉的分享
宝玉的分享
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
U
Unit 42
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
S
SegmentFault 最新的问题
腾讯CDC
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Martin Fowler
Martin Fowler
博客园 - 三生石上(FineUI控件)
Vercel News
Vercel News

Ruby on Rails: Compress the complexity of modern web apps

Safer to_i coercion, custom to_fs formats, and more! This Week in Rails: May 16, 2026 This Week in Rails: May 8, 2026 This Week in Rails: May 1, 2026 Active Record gets better every week Great big Rails World 2026 update: CFP, Corporate Support tickets, workshops Query command for database queries and more Explicit query: and body: kwargs for integration tests and more! Speedup ActiveRecord::LogSubscriber#sql_color and more! This Week in Rails: March 27, 2026 Rails Versions 8.0.5 and 8.1.3 have been released! Rails Versions 7.2.3.1, 8.0.4.1, and 8.1.2.1 have been released! This Week in Rails: March 20, 2026 Validate URI scheme in Action Text and more This Week in Rails: March 6, 2026 Planning Center is the newest Rails Foundation Contributing member Action Text gets Markdown conversion, editor links in devcontainers, and more! BARRA seeks Rails developer Joe Agliozzo is looking for a Rails developer The rise of lighttpd as the alternative web server When longer is better and more is more Snowdevil: First e-tailer on Rails Natural selection for frameworks in Ruby vs Java Address book tutorial in Portuguese Becoming a better programmer with Rails 10 Things Every Java Programmer Should Know About Ruby Really Getting Started in Rails Off the Treadmill, Onto the Rails Rails 0.9.5: A world of fixes and tweaks Rich clients with Rails and XUL
Infer primary_key: :id on associations with composite pri...
David Heinemeier Hansson · 2023-09-08 · via Ruby on Rails: Compress the complexity of modern web apps

Friday, September 8, 2023
Posted by vipulnsward

Hi! This is Vipul bringing you the latest from this week’s changes in the Rails codebase.

Infer primary_key: :id on associations with composite primary key models

Prior to this change, you’d need to do the following to set up associations for composite primary key models:

class Order
  self.primary_key = [:shop_id, :id]
  has_many :order_agreements, primary_key: :id
end

class OrderAgreement
  belongs_to :order, primary_key: :id
end

After this change, the primary_key option no longer needs to be specified:

class Order
  self.primary_key = [:shop_id, :id]
  has_many :order_agreements
end

class OrderAgreement
  belongs_to :order
end

Add validation option for enum to make then validatable without raising error

This change adds :validate option for enums. If you want the enum value to be validated before saving, use the option :validate:

class Conversation < ApplicationRecord
  enum :status, %i[active archived], validate: true
end

conversation = Conversation.new
conversation.status = :unknown
conversation.valid? # => false

It is also possible to pass additional validation options:

class Conversation < ApplicationRecord
  enum :status, %i[active archived], validate: { allow_nil: true }
end

conversation = Conversation.new
conversation.status = nil
conversation.valid? # => true

Otherwise ArgumentError will raise which is standard current behavior:

class Conversation < ApplicationRecord
  enum :status, %i[active archived]
end

conversation = Conversation.new
conversation.status = :unknown # 'unknown' is not a valid status (ArgumentError)

Use SecureRandom.alphanumeric for SecureRandom.base36/base58 in Ruby 3.3

Ruby 3.3 added a change that allows passing a list of characters to SecureRandom.alphanumeric. This change now uses SecureRandom.alphanumeric for SecureRandom.base36/base58 instead of complex SecureRandom.random_number/random_bytes usage as well for a slightly faster solution.

Deprecate passing rewhere to merge

Specifying Relation#merge(rewhere: true) is deprecated, as that has now been the default since Rails 7.0. This change will warn about setting the rewhere option will error in Rails 7.2.

Fix unscope not working when where uses triple dot range

This change fixes unscope not working in specific case for triple dot range. For example:

Before:

Post.where(id: 1...3).unscope(where: :id).to_sql # "SELECT `posts`.* FROM `posts` WHERE `posts`.`id` >= 1 AND `posts`.`id` < 3"    

After:

Post.where(id: 1...3).unscope(where: :id).to_sql # "SELECT `posts`.* FROM `posts`"

Fix change_column not setting precision for sqlite

This change fixes change_column not setting precision: 6 on datetime columns when using 7.0+ Migrations and SQLite.

Change has_secure_token default to on: :initialize

With the changes made in previously, has_secure_token declarations can be configured to execute in an after_initialize callback. This commit adds a new Rails 7.1 default: generate all has_secure_token values when their corresponding models are initialized.

Fix: simple_format with blank wrapper_tag option returns plain html tag

By default simple_format method returns the text wrapped with <p>. But if we explicitly specify the wrapper_tag: nil in the options, it used to return the text wrapped with <></> tag. This change fixes the behaviour to now wrap it in <p> instead.

You can view the whole list of changes here. We had 30 contributors to the Rails codebase this past week!

Until next time!

Subscribe to get these updates mailed to you.