updateメソッド1) Ruby on Railsで、Active Recordオブジェクトの属性を更新し、データベースに保存
2) 二つの使用方法:オブジェクトインスタンス、クラスメソッド
update# IDが1のUserレコード検索
user = User.find(1)
# nameとemail属性更新・保存
user.update(name: "新しい名前", email: "new@example.com")
saveメソッドを内部呼び出し、バリデーション実行false返却、errors属性にエラーメッセージ保存update# IDが1のUserレコード更新
User.update(1, { name: "新しい名前", email: "new@example.com" })
# IDが1と2のレコード更新
User.update([1, 2], [{ name: "最初のユーザー名" }, { name: "二番目のユーザー名" }])
update成功時true、失敗時false返却errors属性でエラー原因確認可能