diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/registrations_controller.rb | 14 | ||||
-rw-r--r-- | app/views/registrations/new.html.erb | 2 |
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" %> |