我正在從一個窗體更新兩個模型的屬性。在更新Rails時顯示來自兩個模型的錯誤消息
User.transaction do
begin
@user.update_attributes!(params[:user])
@board.update_attributes!(params[:board])
rescue ActiveRecord::RecordInvalid
end
end
當@ user.update_attributes產生錯誤時,事務停止,錯誤消息顯示在視圖中。
但是我想嘗試更新@user和@board並獲取兩者的錯誤消息,以便用戶可以一次性更正所有錯誤。
我該怎麼做?
非常感謝您提前。