Complete Lesson 17

main
Simon Quigley 1 year ago
parent 9592b1daa2
commit 93ba30a106

@ -30,6 +30,6 @@ class MoviesController < ApplicationController
private private
def movie_params 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
end end

@ -14,5 +14,14 @@
<%= f.label :total_gross %> <%= f.label :total_gross %>
<%= f.number_field :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 %> <%= f.submit %>
<% end %> <% end %>

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

@ -1,4 +1,7 @@
<section class="movie-details"> <section class="movie-details">
<div class="image">
<%= image_tag @movie.image_file_name %>
</div>
<div class="details"> <div class="details">
<h1><%= @movie.title %></h1> <h1><%= @movie.title %></h1>
<h2> <h2>
@ -8,6 +11,14 @@
<%= @movie.description %> <%= @movie.description %>
</p> </p>
<table> <table>
<tr>
<th>Director:</th>
<td><%= @movie.director %></td>
</tr>
<tr>
<th>Duration:</th>
<td><%= @movie.duration %></td>
</tr>
<tr> <tr>
<th>Total Gross:</th> <th>Total Gross:</th>
<td><%= total_gross(@movie) %></td> <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. # 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| create_table "movies", force: :cascade do |t|
t.string "title" t.string "title"
t.string "rating" 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.datetime "updated_at", null: false
t.text "description" t.text "description"
t.date "released_on" t.date "released_on"
t.string "director"
t.string "duration"
t.string "image_file_name"
end end
end end

Loading…
Cancel
Save