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
3 changes: 3 additions & 0 deletions app/controllers/directors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def destroy
respond_to do |format|
format.html { redirect_to directors_url, notice: "Director was successfully destroyed." }
format.json { head :no_content }
format.js do
render template "directors/destroy.js.erb"
end
end
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def destroy
end
end


private
# Use callbacks to share common setup or constraints between actions.
def set_movie
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
1 change: 1 addition & 0 deletions app/models/movie.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class Movie < ApplicationRecord
belongs_to :director
has_many :characters, dependent: :destroy
end
1 change: 1 addition & 0 deletions app/views/directors/destroy.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#<%= dom_id(@director) %>").remove();
2 changes: 1 addition & 1 deletion app/views/directors/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<td><%= director.dob %></td>
<td><%= link_to 'Show', director %></td>
<td><%= link_to 'Edit', edit_director_path(director) %></td>
<td><%= link_to 'Destroy', director, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to 'Destroy', director, method: :delete, remote: true %></td>
</tr>
<% end %>
</tbody>
Expand Down
4 changes: 4 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

<%= 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
2 changes: 1 addition & 1 deletion app/views/movies/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<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>
<td><%= link_to 'Destroy', movie, method: :delete, remote: true %></td>
</tr>
<% end %>
</tbody>
Expand Down
8 changes: 8 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)


# directors = Director.create([{name: 'George Lucas'}, {name: 'Peter Jackson'}])
movies = Movie.create([{ title: 'Star Wars' }, { title: 'Lord of the Rings' }])
# actors = Actor.create([{name: 'Mark Hamill'}, {name: 'Elijah Wood'}])
# characters = Character.create([{name: 'Luke', movie: movies.first, actor: actors.first}, {name: 'Frodo', movie: movies.second, actor: actors.second}])
# (name: 'Luke', movie: movies.first, actor: actors.first)
# Character.create(name: 'Bilbo', movie: movies.second, actor: actors.second)