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 @@ -27,6 +27,7 @@ def create
if @movie.save
format.html { redirect_to @movie, notice: "Movie was successfully created." }
format.json { render :show, status: :created, location: @movie }
format.js
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @movie.errors, status: :unprocessable_entity }
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.

import Rails from "@rails/ujs"
import Rails, { $ } from "@rails/ujs"; global.Rails = Rails;
import * as ActiveStorage from "@rails/activestorage"
import "channels"

Expand Down
2 changes: 2 additions & 0 deletions app/models/actor.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
class Actor < ApplicationRecord
has_many :characters

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
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
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.js"
integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk="
crossorigin="anonymous">
</script>
</head>

<body>
Expand Down
18 changes: 18 additions & 0 deletions app/views/movies/create.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var body = $("#movie_body");

var added_movie = '<tr>' +
'<td>' + <%=@movie.title%> + '</td>' +
'<td>' + <%=@movie.description%> + '</td>' +
'<td>' + <%=@movie.duration%> + '</td>' +
'<td>' + <%=@movie.year%> + '</td>' +
'<td>' + <%=@movie.director_id%> + '</td>' +
'<td>' + <%=@movie.title%> + '</td>' +
'<td>' + '<%= j(link_to 'Show', @movie) %>' + '</td>' +
'<td>' + '<%= j(link_to 'Edit', edit_movie_path(@movie)) %>' + '</td>' +
'<td>' + '<%= j(link_to 'Destroy', @movie, method: :delete, data: { confirm: 'Are you sure?' }) %>' + '</td>' +
'</tr>';

var movie = $(added_movie);
movie.hide();
body.after(movie);
movie.fadeIn(5000);
13 changes: 12 additions & 1 deletion app/views/movies/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@
<th>Director</th>
<th colspan="3"></th>
</tr>

<tr id="new_movie_form">
<%=form_with(model: Movie.new, local: false) do |form|%>
<th id="new_movie_title"><%= form.text_field :title %></th>
<th id="new_movie_description"><%= form.text_area :description %></th>
<th id="new_movie_duration"><%= form.number_field :duration %></th>
<th id="new_movie_year"><%= form.number_field :year %></th>
<th id="new_movie_director_id"><%= form.text_field :director_id %></th>
<th class="actions"><%=form.submit%></th>
<%end%>
</tr>
</thead>

<tbody>
<tbody id="movie_body">
<% @movies.each do |movie| %>
<tr>
<td><%= movie.title %></td>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"@rails/actioncable": "^6.0.0",
"@rails/activestorage": "^6.0.0",
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "5.2.1"
"@rails/webpacker": "5.2.1",
"jquery": "^3.6.0"
},
"version": "0.1.0",
"devDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.