Complete Lesson 18

This commit is contained in:
Simon Quigley 2023-09-25 16:08:33 -05:00
parent 93ba30a106
commit db77371820
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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 %>