Skip to content

Commit

Permalink
exercise iteration 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Antis committed Feb 23, 2021
1 parent cce132a commit 63c1ca3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class User < ApplicationRecord
validates :username, :email, :password, presence: true
end
24 changes: 24 additions & 0 deletions app/views/users/new.html.haml
Original file line number Diff line number Diff line change
@@ -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" }
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 63c1ca3

Please sign in to comment.