LoginSignup
0
0

バリデーションやエラーメッセージ

Last updated at Posted at 2021-03-02

バリデーションはモデルで設定する
validates :name, {ここに書いていく}
validates :content, {presence: true, length:{maximum: 10}}
content : バリデーションをかけるカラム

バリデーションでfefefe.saveなどが失敗した場合は
fefefe.errors.full_messages
の中にバリデーションで引っかかったエラーの内容が自動的にはいる

<% @post.errors.full_messages.each do |message| %>
     <%= message %>
<% end %>

####バリデーションの種類####
presence: true 入力チェック
length:{maximum: 10} 文字数チェック
uniqueness: true 重複チェック

0
0
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
0
0