From 93ba30a106a9393ae31d34da4a6b0e7de9a444e6 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Mon, 25 Sep 2023 16:04:41 -0500 Subject: [PATCH] Complete Lesson 17 --- app/controllers/movies_controller.rb | 2 +- app/views/movies/_form.html.erb | 9 ++++ app/views/movies/index.html.erb | 42 ++++++++++--------- app/views/movies/show.html.erb | 11 +++++ ...0230925205851_add_more_fields_to_movies.rb | 7 ++++ db/schema.rb | 5 ++- 6 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 db/migrate/20230925205851_add_more_fields_to_movies.rb diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 70d719e..575df53 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -30,6 +30,6 @@ class MoviesController < ApplicationController private def movie_params - params.require(:movie).permit(:title, :description, :rating, :released_on, :total_gross) + params.require(:movie).permit(:title, :description, :rating, :released_on, :total_gross, :director, :duration, :image_file_name) end end diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb index 17cbca9..0d50b62 100644 --- a/app/views/movies/_form.html.erb +++ b/app/views/movies/_form.html.erb @@ -14,5 +14,14 @@ <%= f.label :total_gross %> <%= f.number_field :total_gross %> + <%= f.label :director %> + <%= f.text_field :director %> + + <%= f.label :duration %> + <%= f.text_field :duration %> + + <%= f.label :image_file_name %> + <%= f.text_field :image_file_name %> + <%= f.submit %> <% end %> diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index b75de10..b03bf33 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -1,23 +1,25 @@
- - -
- <%= link_to "Add New Movie", new_movie_path, class: "button" %> +
    + <% @movies.each do |movie| %> +
    +
    + <%= image_tag movie.image_file_name %> +
    +
    +

    + <%= link_to(movie.title, movie_path(movie)) %> +

    +

    + <%= total_gross(movie) %> +

    +

    + <%= truncate(movie.description, length: 150, separator: ' ') %> +

    +
    + <% end %> +
+
+ <%= link_to "Add New Movie", new_movie_path, class: "button" %> +
diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 011fe23..d54d205 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -1,4 +1,7 @@
+
+ <%= image_tag @movie.image_file_name %> +

<%= @movie.title %>

@@ -8,6 +11,14 @@ <%= @movie.description %>

+ + + + + + + + diff --git a/db/migrate/20230925205851_add_more_fields_to_movies.rb b/db/migrate/20230925205851_add_more_fields_to_movies.rb new file mode 100644 index 0000000..7a15a2a --- /dev/null +++ b/db/migrate/20230925205851_add_more_fields_to_movies.rb @@ -0,0 +1,7 @@ +class AddMoreFieldsToMovies < ActiveRecord::Migration[7.0] + def change + add_column :movies, :director, :string + add_column :movies, :duration, :string + add_column :movies, :image_file_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 7254875..d292225 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_09_25_183426) do +ActiveRecord::Schema[7.0].define(version: 2023_09_25_205851) do create_table "movies", force: :cascade do |t| t.string "title" t.string "rating" @@ -19,6 +19,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_25_183426) do t.datetime "updated_at", null: false t.text "description" t.date "released_on" + t.string "director" + t.string "duration" + t.string "image_file_name" end end
Director:<%= @movie.director %>
Duration:<%= @movie.duration %>
Total Gross: <%= total_gross(@movie) %>