2
1

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 3 years have passed since last update.

Rails | モデルの validate 文が効かない?

2
Last updated at Posted at 2015-12-07

validate (単数形) ではなく validates (複数形) で書くこと。

models/example.rb
class Example < ActiveRecord::Base
-  validate :user_id, presence: true
+  validates :user_id, presence: true
end

この場合 :user_id がたまたまアクセサとして存在すると、validate (単数形) で書いても何のエラーも起こらないようなので注意。(コメント参照)

環境

  • Rails 4.0.13

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

メンター受付

2
1
1

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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?