Complete Lesson 28

main
Simon Quigley 1 year ago
parent 09eda4f4e0
commit fa03c12ab4

@ -6,7 +6,7 @@ class UsersController < ApplicationController
@user = User.new @user = User.new
end end
def show def show
@user = User.find(params[:id]) set_user
end end
def create def create
@user = User.new(user_params) @user = User.new(user_params)
@ -16,8 +16,27 @@ class UsersController < ApplicationController
render :new, status: :unprocessable_entity render :new, status: :unprocessable_entity
end end
end end
def edit
set_user
end
def update
set_user
if @user.update(user_params)
redirect_to @user, notice: "Account successfully updated!"
else
render :new, status: :unprocessable_entity
end
end
def destroy
set_user
@user.destroy
redirect_to movies_url, status: :see_other, alert: "Account successfully deleted!"
end
private private
def set_user
@user = User.find(params[:id])
end
def user_params def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation) params.require(:user).permit(:name, :email, :password, :password_confirmation)

@ -13,5 +13,9 @@
<%= f.label :password_confirmation, "Confirm Password" %> <%= f.label :password_confirmation, "Confirm Password" %>
<%= f.password_field :password_confirmation %> <%= f.password_field :password_confirmation %>
<%= f.submit %> <% if user.new_record? %>
<%= f.submit "Create Account" %>
<% else %>
<%= f.submit "Update Account" %>
<% end %>
<% end %> <% end %>

@ -0,0 +1,3 @@
<h1>Edit Account</h1>
<%= render "form", user: @user %>

@ -1,4 +1,8 @@
<section class="user"> <section class="user">
<h1><%= @user.name %></h1> <h1><%= @user.name %></h1>
<h2><%= mail_to(@user.email) %></h2> <h2><%= mail_to(@user.email) %></h2>
<div class="actions">
<%= link_to "Edit Account", edit_user_path(@user), class: "button edit" %>
<%= link_to "Delete Account", user_path(@user), class: "button delete", data: { turbo_method: :delete, turbo_confirm: "Permanently delete your account!?" } %>
</div>
</section> </section>

Loading…
Cancel
Save