限制數量的 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 目錄,方便在後續執行時使用快取。