Complete Lesson 13

main
Simon Quigley 8 months ago
parent 2b32bc0e62
commit a5018ba917

@ -13,8 +13,21 @@ class MoviesController < ApplicationController
end
def update
@movie = Movie.find(params[:id])
movie_params = params.require(:movie).permit(:title, :description, :rating, :released_on, :total_gross)
@movie.update(movie_params)
redirect_to @movie
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

@ -17,4 +17,7 @@
</section>
<% end %>
</ul>
<section class="admin">
<%= link_to "Add New Movie", new_movie_path, class: "button" %>
</section>
</div>

@ -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
root "movies#index"
get "movies" => "movies#index"
get "movies/:id" => "movies#show", as: "movie"
patch "movies/:id" => "movies#update"
get "movies/:id/edit" => "movies#edit", as: "edit_movie"
resources :movies
end

Loading…
Cancel
Save