限制数量的 has_many 关联
October 13, 2020
# app/models/user.rb
has_one :four_car_garage
has_many :cars
validates :cars, length: { maximum: 4 }
# app/models/user.rb
has_one :four_car_garage
has_many :cars
validates :cars, length: { maximum: 4 }
要管理 permitted params,你可以在你的 policy 中加入 permitted\attributes 和 permitted\attributes\for\#{action},例如
Turbo 会监听 form 上的 submit 事件。因此,用 JS 提交表单时,请一律使用 requestSubmit。
Rails 项目在 GitHub actions 中通常会把 gems 安装到 vendor 目录,方便在后续运行时使用缓存。