aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-11-11 20:25:57 +0000
committerMatthew Lemon <y@yulqen.org>2024-11-11 20:25:57 +0000
commit8ef8a8661bf4663e776497c3cbc55e3dceb63481 (patch)
tree1db4c5311210c1a38f9e8815d8f37a38cf4b6427
parent6c13cfb192ab4250e446f2d2212a701ffbd447e8 (diff)
Can now sign up
-rw-r--r--app/controllers/registrations_controller.rb14
-rw-r--r--app/views/registrations/new.html.erb2
2 files changed, 15 insertions, 1 deletions
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index 13ef4dd..ee0d70e 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -1,8 +1,22 @@
class RegistrationsController < 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 \ No newline at end of file
diff --git a/app/views/registrations/new.html.erb b/app/views/registrations/new.html.erb
index 3663e5f..14318df 100644
--- a/app/views/registrations/new.html.erb
+++ b/app/views/registrations/new.html.erb
@@ -11,7 +11,7 @@
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
<% end %>
- <%= form_with url: registration_url, class: "contents" do |form| %>
+ <%= form_with url: registration_url, model: @user, class: "contents" do |form| %>
<div class="my-5">
<%= label_tag "first_name", nil, class: "font-bold text-gray-700" %>
<%= form.text_field :first_name, required: true, autofocus: true, autocomplete: "first_name", placeholder: "Enter your first name", value: params[:first_name], class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>