diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..e351897 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,10 @@ +class UsersController < ApplicationController + + def create + @user = User.new(username: params[:user][:username], email: params[:user][:email], password: params[:user][:password]) + redirect_to new_user_path and return if @user.save + flash.now[:alert] = "#{@user.errors.full_messages}" + render :new + end + +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..396b93d --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,3 @@ +class User < ApplicationRecord + validates :username, :email, :password, presence: true +end diff --git a/app/views/users/new.html.haml b/app/views/users/new.html.haml new file mode 100644 index 0000000..9391658 --- /dev/null +++ b/app/views/users/new.html.haml @@ -0,0 +1,24 @@ +%br +%br +%h1 Create user +%br +%br +%form{ "method" => "post", "action" => "/users", "accept-charset" => "UTF-8"} + %input{ "type" => "hidden", "name" => "authenticity_token", "value" => form_authenticity_token } + %label{ :for => "username" }User name + %input{ :type => "text", :name => "user[username]", :id => "username" } + %br + %br + %label{ :for => "email" } E-mail + %input{ :type => "text", :name => "user[email]", :id => "email" } + %br + %br + %label{ :for => "password" } Password + %input{ :type => "password" , :name => "user[password]", :id => "password" } + %br + %br + - flash.each do |type, msg| + %br + %code= msg + %br + %input{ :type => "submit" } diff --git a/config/routes.rb b/config/routes.rb index c06383a..feb0a5b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,3 @@ Rails.application.routes.draw do - # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html + resources :users, only: [:new, :create] end