From 5095f63fd72e978d2b6a883e85bff928cb55a7f4 Mon Sep 17 00:00:00 2001 From: Karol Selak Date: Sun, 21 Mar 2021 17:06:54 +0100 Subject: [PATCH] book and author validation --- app/models/author.rb | 2 ++ app/models/book.rb | 3 +++ 2 files changed, 5 insertions(+) diff --git a/app/models/author.rb b/app/models/author.rb index e399202..9f3a806 100644 --- a/app/models/author.rb +++ b/app/models/author.rb @@ -1,2 +1,4 @@ class Author < ApplicationRecord + validates :first_name, presence: true + validates :last_name, presence: true end diff --git a/app/models/book.rb b/app/models/book.rb index 1b16bc8..860c5d5 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -2,4 +2,7 @@ class Book < ApplicationRecord has_and_belongs_to_many :authors scope :published, -> { where(published: true) } + validates :title, presence: true + validates :price, presence: true + validates :published, presence: true end