Complete Lesson 13
This commit is contained in:
parent
2b32bc0e62
commit
a5018ba917
@ -13,8 +13,21 @@ class MoviesController < ApplicationController
|
|||||||
end
|
end
|
||||||
def update
|
def update
|
||||||
@movie = Movie.find(params[:id])
|
@movie = Movie.find(params[:id])
|
||||||
movie_params = params.require(:movie).permit(:title, :description, :rating, :released_on, :total_gross)
|
|
||||||
@movie.update(movie_params)
|
@movie.update(movie_params)
|
||||||
redirect_to @movie
|
redirect_to @movie
|
||||||
end
|
end
|
||||||
|
def new
|
||||||
|
@movie = Movie.new
|
||||||
|
end
|
||||||
|
def create
|
||||||
|
@movie = Movie.new(movie_params)
|
||||||
|
@movie.save
|
||||||
|
redirect_to @movie
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def movie_params
|
||||||
|
params.require(:movie).permit(:title, :description, :rating, :released_on, :total_gross)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,4 +17,7 @@
|
|||||||
</section>
|
</section>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
<section class="admin">
|
||||||
|
<%= link_to "Add New Movie", new_movie_path, class: "button" %>
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
20
app/views/movies/new.html.erb
Normal file
20
app/views/movies/new.html.erb
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<h1>Creating a New Movie</h1>
|
||||||
|
|
||||||
|
<%= form_with(model: @movie) do |f| %>
|
||||||
|
<%= f.label :title %>
|
||||||
|
<%= f.text_field :title %>
|
||||||
|
|
||||||
|
<%= f.label :description %>
|
||||||
|
<%= f.text_area :description, rows: 7 %>
|
||||||
|
|
||||||
|
<%= f.label :rating %>
|
||||||
|
<%= f.text_field :rating %>
|
||||||
|
|
||||||
|
<%= f.label :released_on %>
|
||||||
|
<%= f.date_field :released_on %>
|
||||||
|
|
||||||
|
<%= f.label :total_gross %>
|
||||||
|
<%= f.number_field :total_gross %>
|
||||||
|
|
||||||
|
<%= f.submit %>
|
||||||
|
<% end %>
|
@ -1,7 +1,5 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
root "movies#index"
|
root "movies#index"
|
||||||
get "movies" => "movies#index"
|
|
||||||
get "movies/:id" => "movies#show", as: "movie"
|
resources :movies
|
||||||
patch "movies/:id" => "movies#update"
|
|
||||||
get "movies/:id/edit" => "movies#edit", as: "edit_movie"
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user