-
- Downloads
Context:
- You are working on a project that involves a web application. - The application uses a database to store user data. - You are implementing a feature that allows users to update their profile information. - The diffs include changes to the user profile update form and the backend logic to handle the update. Diffs: ```diff diff --git a/app/models/user.rb b/app/models/user.rb index 1234567..89abcde 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,7 @@ class User < ApplicationRecord # User attributes + attribute :name, :string + attribute :email, :string # Validations validates :name, presence: true diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 7654321..8765432 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -1,5 +1,7 @@ <h1>Edit Profile</h1> +<%= form.label :name %> +<%= form.text_field :name %> <%= form.label :email %> <%= form.text_field :email %> diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3456789..9876543 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,7 @@ class UsersController < ApplicationController before_action :set_user, only: [:show, :edit, :update, :destroy] + def update + @user.update(user_params) + redirect_to @user + end + private def set_user @@ -8,4 +10,6 @@ class UsersController < ApplicationController params.require(:user).permit(:name, :email) end end + +# Add user_params method to allow name and email attributes ``` Commit message: ``` feat: add name and email attributes to user model and update user profile form ```
Please register or sign in to comment