Complete Lesson 28
This commit is contained in:
parent
09eda4f4e0
commit
fa03c12ab4
@ -6,7 +6,7 @@ class UsersController < ApplicationController
|
||||
@user = User.new
|
||||
end
|
||||
def show
|
||||
@user = User.find(params[:id])
|
||||
set_user
|
||||
end
|
||||
def create
|
||||
@user = User.new(user_params)
|
||||
@ -16,8 +16,27 @@ class UsersController < ApplicationController
|
||||
render :new, status: :unprocessable_entity
|
||||
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
|
||||
def set_user
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:name, :email, :password, :password_confirmation)
|
||||
|
@ -13,5 +13,9 @@
|
||||
<%= f.label :password_confirmation, "Confirm Password" %>
|
||||
<%= f.password_field :password_confirmation %>
|
||||
|
||||
<%= f.submit %>
|
||||
<% if user.new_record? %>
|
||||
<%= f.submit "Create Account" %>
|
||||
<% else %>
|
||||
<%= f.submit "Update Account" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
3
app/views/users/edit.html.erb
Normal file
3
app/views/users/edit.html.erb
Normal file
@ -0,0 +1,3 @@
|
||||
<h1>Edit Account</h1>
|
||||
|
||||
<%= render "form", user: @user %>
|
@ -1,4 +1,8 @@
|
||||
<section class="user">
|
||||
<h1><%= @user.name %></h1>
|
||||
<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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user