From db773718200f8b89395baa0d19a9347bb52be74e Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Mon, 25 Sep 2023 16:08:33 -0500 Subject: [PATCH] Complete Lesson 18 --- app/models/movie.rb | 10 ++++++++++ app/views/movies/_form.html.erb | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/movie.rb b/app/models/movie.rb index 1f8f0e5..36ce580 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -1,4 +1,14 @@ class Movie < ApplicationRecord + validates :title, :released_on, :duration, presence: true + validates :description, length: { minimum: 25 } + validates :total_gross, numericality: { greater_than_or_equal_to: 0 } + validates :image_file_name, format: { + with: /\w+\.(jpg|png)\z/i, + message: "must be a JPG or PNG image" + } + RATINGS = %w(G PG PG-13 R X NC-17) + validates :rating, inclusion: { in: RATINGS } + def flop? total_gross.blank? || total_gross < 225_000_000 end diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb index 0d50b62..0a510ff 100644 --- a/app/views/movies/_form.html.erb +++ b/app/views/movies/_form.html.erb @@ -6,7 +6,7 @@ <%= f.text_area :description, rows: 10 %> <%= f.label :rating %> - <%= f.text_field :rating %> + <%= f.select :rating, Movie::RATINGS, prompt: "Pick one" %> <%= f.label :released_on %> <%= f.date_field :released_on %>