0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

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

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?