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

Validation

Last updated at Posted at 2017-12-24
# プロジェクト、コントローラの作成
rails new ValidationTest  -d mysql
cd ValidationTest
rails g controller ValidationTestApp index show

(config/database.yml を編集)

rails db:create

rails generate scaffold Person name:string gender:string age:integer
rails db:migrate

XXX.XXX.XXX.XXX/people
にアクセスしてTopページを確認する。

# Validateを設定する
app/models/person.rb
class Person < ApplicationRecord
  validates :name, presence: true
end

実際にnameを空にしてsubmitしてみる。
以下のようなエラーが出力される。

image.png


「Active Record(Railsのモデル) バリデーションまとめ」
http://morizyun.github.io/ruby/active-record-validation.html

「Rails 4でモデルのバリデーションまとめ」
http://ruby-rails.hatenadiary.com/entry/20140724/1406145303#model-validation-definettions

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?