Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def destroy
respond_to do |format|
format.html { redirect_to movies_url, notice: "Movie was successfully destroyed." }
format.json { head :no_content }
format.js
end
end

Expand Down
1 change: 1 addition & 0 deletions app/models/actor.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class Actor < ApplicationRecord
has_many :characters, dependent: :destroy
end
1 change: 1 addition & 0 deletions app/models/director.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class Director < ApplicationRecord
has_many :movies, dependent: :destroy
end
2 changes: 2 additions & 0 deletions app/models/movie.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class Movie < ApplicationRecord
belongs_to :director

has_many :characters, dependent: :destroy
end
5 changes: 5 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_pack_tag 'application' %>

<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"></script>
</head>

<body>
Expand Down
10 changes: 10 additions & 0 deletions app/views/movies/_movie.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<tr id="<%= dom_id(movie) %>">
<td><%= movie.title %></td>
<td><%= movie.description %></td>
<td><%= movie.duration %></td>
<td><%= movie.year %></td>
<td><%= movie.director_id %></td>
<td><%= link_to 'Show', movie %></td>
<td><%= link_to 'Edit', edit_movie_path(movie) %></td>
<td><%= link_to 'Destroy', movie, method: :delete, remote: true %></td>
</tr>
3 changes: 3 additions & 0 deletions app/views/movies/destroy.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$("#<%= dom_id(@movie) %>").fadeOut(function() {
$(this).remove();
});
13 changes: 1 addition & 12 deletions app/views/movies/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,7 @@
</thead>

<tbody>
<% @movies.each do |movie| %>
<tr>
<td><%= movie.title %></td>
<td><%= movie.description %></td>
<td><%= movie.duration %></td>
<td><%= movie.year %></td>
<td><%= movie.director_id %></td>
<td><%= link_to 'Show', movie %></td>
<td><%= link_to 'Edit', edit_movie_path(movie) %></td>
<td><%= link_to 'Destroy', movie, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
<%= render @movies %>
</tbody>
</table>

Expand Down
Loading