diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bc85b72..87bf36a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -22,6 +22,21 @@ class UsersController < ApplicationController end end + def edit + @user = User.find(params[:id]) + end + + def update + @user = User.find(params[:id]) + if @user.update(user_params) + flash[:success] = "Profile updated" + redirect_to @user + # redirect_to user_url(@user) + else + render 'edit' + end + end + private def user_params diff --git a/app/models/user.rb b/app/models/user.rb index aec527c..1f45758 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,7 +8,7 @@ class User < ApplicationRecord format: { with: VALID_EMAIL_REGEX }, uniqueness: true has_secure_password - validates :password, presence: true, length: { minimum: 6 } + validates :password, presence: true, length: { minimum: 6 }, allow_nil: true def User.digest(string) cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 4f128d7..fa4e5b5 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -25,7 +25,7 @@