guides.rubyonrails.org/active_record_validations.html

 

Active Record Validations — Ruby on Rails Guides

Active Record ValidationsThis guide teaches you how to validate the state of objects before they go into the database using Active Record's validations feature.After reading this guide, you will know: How to use the built-in Active Record validation helper

guides.rubyonrails.org

>reload!

# rails console reload

 

models>article.rb에서 validation 수정

예시

class Article < ApplicationRecord
  validates :title, presence: true, length: { minimum: 6, maximum: 100}
  validates :description, presence: true, length: { minimum: 10, maximum: 300}
end
>article = Article.new
>article.title = "a"
>article.description = "b"
>article.save
>article.errors.full_messages

'ruby on rails' 카테고리의 다른 글

REST to CRUD  (0) 2020.11.11
debugging & route, action, view  (0) 2020.11.10
Models and rails console  (0) 2020.11.10
rails naming conventions & migration  (0) 2020.11.10
CRUD in rails  (0) 2020.11.10

+ Recent posts