From 6676d7cbd85a42de043b0ed1769e82a12a1cb035 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Wed, 20 Nov 2024 20:48:22 +0000 Subject: Adds a users controller to fix sign-up bug --- app/controllers/users_controller.rb | 22 ++++++++++++++++++++++ app/views/registrations/new.html.erb | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 app/controllers/users_controller.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..c49a295 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,22 @@ +class UsersController < ApplicationController + allow_unauthenticated_access only: %i[ new create ] + def new + @user = User.new + end + + def create + @user = User.create(user_params) + if @user.save + start_new_session_for @user + redirect_to root_path, notice: "Successfully signed up!" + else + render :new + end + end + + private + + def user_params + params.expect(user: [:first_name, :last_name, :email_address, :password, :password_confirmation]) + end +end diff --git a/app/views/registrations/new.html.erb b/app/views/registrations/new.html.erb index f70d143..3edc66f 100644 --- a/app/views/registrations/new.html.erb +++ b/app/views/registrations/new.html.erb @@ -48,4 +48,4 @@ <% end %>
- \ No newline at end of file + -- cgit v1.2.3