LoginSignup
1
1

rails バリデーション機能について

Posted at

結論

validation:検証

オブジェクト(Hoge.newなどで生成されたものなど)がデータベースに保存される(newだけでは保存されない、save,
criate,updateメソッドで初めてデータベースに保存される)前に、本当にデータベースに保存していいのか検証してくれる機能

とてもシンプル

app/models/hoge.rb
class Hoge < ApplicationRecord
  validate :カラム名,presence: true
end

presence: 出席する = 空文字を防ぐ

もしユーザーが空文字を入力していたら?

nil => false 

と判断される。

バリデーションヘルパー

目次.2 で詳細が記載されています。
https://railsguides.jp/active_record_validations.html

以上です。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1