Complete Lesson 17

main
Simon Quigley 8 months ago
parent 9592b1daa2
commit 93ba30a106

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

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

@ -1,23 +1,25 @@
<div class="container">
<ul>
<% @movies.each do |movie| %>
<section class="movie">
<div class="summary">
<h2>
<%= link_to(movie.title, movie_path(movie)) %>
</h2>
<h3>
<%= total_gross(movie) %>
</h3>
<p>
<%= truncate(movie.description, length: 150, separator: ' ') %>
</p>
</div>
</section>
<% end %>
</ul>
<section class="admin">
<%= link_to "Add New Movie", new_movie_path, class: "button" %>
<ul>
<% @movies.each do |movie| %>
<section class="movie">
<div class="image">
<%= image_tag movie.image_file_name %>
</div>
<div class="summary">
<h2>
<%= link_to(movie.title, movie_path(movie)) %>
</h2>
<h3>
<%= total_gross(movie) %>
</h3>
<p>
<%= truncate(movie.description, length: 150, separator: ' ') %>
</p>
</div>
</section>
<% end %>
</ul>
<section class="admin">
<%= link_to "Add New Movie", new_movie_path, class: "button" %>
</section>
</div>

@ -1,4 +1,7 @@
<section class="movie-details">
<div class="image">
<%= image_tag @movie.image_file_name %>
</div>
<div class="details">
<h1><%= @movie.title %></h1>
<h2>
@ -8,6 +11,14 @@
<%= @movie.description %>
</p>
<table>
<tr>
<th>Director:</th>
<td><%= @movie.director %></td>
</tr>
<tr>
<th>Duration:</th>
<td><%= @movie.duration %></td>
</tr>
<tr>
<th>Total Gross:</th>
<td><%= total_gross(@movie) %></td>

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

5
db/schema.rb generated

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

Loading…
Cancel
Save