Complete Lesson 19

main
Simon Quigley 1 year ago
parent db77371820
commit 1656289d7d

@ -10,16 +10,22 @@ class MoviesController < ApplicationController
end
def update
@movie = Movie.find(params[:id])
@movie.update(movie_params)
if @movie.update(movie_params)
redirect_to @movie
else
render :edit, status: :unprocessable_entity
end
end
def new
@movie = Movie.new
end
def create
@movie = Movie.new(movie_params)
@movie.save
if @movie.save
redirect_to @movie
else
render :new, status: :unprocessable_entity
end
end
def destroy
@movie = Movie.find(params[:id])

@ -1,4 +1,6 @@
<%= form_with(model: movie) do |f| %>
<%= render "shared/errors", object: movie %>
<%= f.label :title %>
<%= f.text_field :title, autofocus: true %>

@ -0,0 +1,16 @@
<% if object.errors.any? %>
<section class="errors">
<h2>
Oops! Your form could not be saved.
</h2>
<h3>
Please correct the following
<%= pluralize(object.errors.size, "error") %>:
</h3>
<ul>
<% object.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</section>
<% end %>
Loading…
Cancel
Save