Skip to content

Commit 5f19384

Browse files
committed
Finish up
1 parent 9183e72 commit 5f19384

File tree

8 files changed

+84
-143
lines changed

8 files changed

+84
-143
lines changed

app/controllers/movies_controller.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class MoviesController < ApplicationController
2+
before_action :set_movie, only: [:show, :edit, :update, :destroy]
3+
24
def new
35
@movie = Movie.new
46
end
@@ -14,12 +16,9 @@ def index
1416
end
1517

1618
def show
17-
@movie = Movie.find(params.fetch(:id))
1819
end
1920

2021
def create
21-
movie_params = params.require(:movie).permit(:title, :description)
22-
2322
@movie = Movie.new(movie_params)
2423

2524
if @movie.valid?
@@ -32,14 +31,9 @@ def create
3231
end
3332

3433
def edit
35-
@movie = Movie.find(params.fetch(:id))
3634
end
3735

3836
def update
39-
@movie = Movie.find(params.fetch(:id))
40-
41-
movie_params = params.require(:movie).permit(:title, :description)
42-
4337
if @movie.update(movie_params)
4438
redirect_to @movie, notice: "Movie updated successfully."
4539
else
@@ -48,10 +42,18 @@ def update
4842
end
4943

5044
def destroy
51-
@movie = Movie.find(params.fetch(:id))
52-
5345
@movie.destroy
5446

5547
redirect_to movies_url, notice: "Movie deleted successfully."
5648
end
49+
50+
private
51+
52+
def movie_params
53+
movie_params = params.require(:movie).permit(:title, :description)
54+
end
55+
56+
def set_movie
57+
@movie = Movie.find(params.fetch(:id))
58+
end
5759
end

app/views/movies/_form.html.erb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%= form_with model: foo do |form| %>
2+
<div>
3+
<%= form.label :title %>
4+
<%= form.text_field :title %>
5+
</div>
6+
7+
<div>
8+
<%= form.label :description %>
9+
<%= form.text_area :description %>
10+
</div>
11+
12+
<div>
13+
<%= form.submit %>
14+
</div>
15+
<% end %>

app/views/movies/_movie_card.html.erb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<div class="card">
2+
<div class="card-header">
3+
<%= link_to "Movie ##{baz.id}", baz %>
4+
</div>
5+
6+
<div class="card-body">
7+
<dl>
8+
<dt>
9+
Title
10+
</dt>
11+
<dd>
12+
<%= baz.title %>
13+
</dd>
14+
15+
<dt>
16+
Description
17+
</dt>
18+
<dd>
19+
<%= baz.description %>
20+
</dd>
21+
</dl>
22+
23+
<div class="row">
24+
<div class="col">
25+
<div class="d-grid">
26+
<%= link_to edit_movie_path(baz), class: "btn btn-outline-secondary" do %>
27+
<i class="fa-regular fa-pen-to-square"></i>
28+
<% end %>
29+
</div>
30+
</div>
31+
<div class="col">
32+
<div class="d-grid">
33+
<%= link_to baz, method: :delete, class: "btn btn-outline-secondary" do %>
34+
<i class="fa-regular fa-trash-can"></i>
35+
<% end %>
36+
</div>
37+
</div>
38+
</div>
39+
</div>
40+
41+
<div class="card-footer">
42+
Last updated <%= time_ago_in_words(baz.updated_at) %> ago
43+
</div>
44+
</div>

app/views/movies/edit.html.erb

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,4 @@
44
<p style="color: red;"><%= message %></p>
55
<% end %>
66

7-
<%= form_with model: @movie do |form| %>
8-
<div>
9-
<%= form.label :title %>
10-
<%= form.text_field :title %>
11-
</div>
12-
13-
<div>
14-
<%= form.label :description %>
15-
<%= form.text_area :description %>
16-
</div>
17-
18-
<div>
19-
<%= form.submit %>
20-
</div>
21-
<% end %>
7+
<%= render partial: "movies/form", locals: { foo: @movie } %>

app/views/movies/index.html.erb

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,10 @@
1010

1111
<hr>
1212

13-
<table>
14-
<tr>
15-
<th>
16-
ID
17-
</th>
18-
19-
<th>
20-
Title
21-
</th>
22-
23-
<th>
24-
Description
25-
</th>
26-
27-
<th>
28-
Created at
29-
</th>
30-
31-
<th>
32-
Updated at
33-
</th>
34-
35-
<th>
36-
</th>
37-
</tr>
38-
13+
<div class="row">
3914
<% @movies.each do |movie| %>
40-
<tr>
41-
<td>
42-
<%= movie.id %>
43-
</td>
44-
45-
<td>
46-
<%= movie.title %>
47-
</td>
48-
49-
<td>
50-
<%= movie.description %>
51-
</td>
52-
53-
<td>
54-
<%= time_ago_in_words(movie.created_at) %> ago
55-
</td>
56-
<td>
57-
<%= time_ago_in_words(movie.updated_at) %> ago
58-
</td>
59-
60-
<td>
61-
<%= link_to "Show details", movie %>
62-
</td>
63-
</tr>
15+
<div class="col-md-3">
16+
<%= render partial: "movies/movie_card", locals: { baz: movie } %>
17+
</div>
6418
<% end %>
65-
</table>
19+
</div>

app/views/movies/new.html.erb

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,4 @@
44
<p style="color: red;"><%= message %></p>
55
<% end %>
66

7-
<%= form_with model: @movie do |form| %>
8-
<div>
9-
<%= form.label :title %>
10-
<%= form.text_field :title %>
11-
</div>
12-
13-
<div>
14-
<%= form.label :description %>
15-
<%= form.text_area :description %>
16-
</div>
17-
18-
<div>
19-
<%= form.submit %>
20-
</div>
21-
<% end %>
7+
<%= render partial: "movies/form", locals: { foo: @movie } %>

app/views/movies/show.html.erb

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,5 @@
1-
<div>
2-
<div>
3-
<h1>
4-
Movie #<%= @movie.id %> details
5-
</h1>
6-
7-
<div>
8-
<div>
9-
<%= link_to "Go back", movies_path %>
10-
</div>
11-
12-
<div>
13-
<%= link_to "Edit Movie", edit_movie_path(@movie) %>
14-
</div>
15-
16-
<div>
17-
<%= link_to "Delete Movie", @movie, method: :delete %>
18-
</div>
19-
</div>
20-
21-
<dl>
22-
<dt>
23-
Title
24-
</dt>
25-
<dd>
26-
<%= @movie.title %>
27-
</dd>
28-
29-
<dt>
30-
Description
31-
</dt>
32-
<dd>
33-
<%= @movie.description %>
34-
</dd>
35-
36-
<dt>
37-
Created at
38-
</dt>
39-
<dd>
40-
<%= time_ago_in_words(@movie.created_at) %> ago
41-
</dd>
42-
43-
<dt>
44-
Updated at
45-
</dt>
46-
<dd>
47-
<%= time_ago_in_words(@movie.updated_at) %> ago
48-
</dd>
49-
</dl>
1+
<div class="row">
2+
<div class="col-md-6 offset-md-3">
3+
<%= render partial: "movies/movie_card", locals: { baz: @movie } %>
504
</div>
515
</div>

app/views/shared/_cdn_assets.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!-- Connect Bootstrap CSS -->
2-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
2+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
33

44
<!-- Connect Bootstrap JavaScript and its dependencies -->
5-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
5+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.min.js"></script>
66

77
<!-- Connect Font Awesome -->
8-
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/js/all.min.js"></script>
8+
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/js/all.min.js"></script>

0 commit comments

Comments
 (0)