Skip to content

Commit be0b99e

Browse files
authored
Merge pull request #5 from lexxeice/sign-up
Finish user signup
2 parents 17f9bc5 + a4f74e1 commit be0b99e

File tree

9 files changed

+148
-17
lines changed

9 files changed

+148
-17
lines changed

app/assets/stylesheets/custom.css.scss

+64
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55

66
$gray-medium-light: #eaeaea;
77

8+
@mixin box_sizing {
9+
-moz-box-sizing: border-box;
10+
-webkit-box-sizing: border-box;
11+
box-sizing: border-box;
12+
}
13+
14+
815
/* universal */
916

1017
body {
@@ -88,3 +95,60 @@ footer {
8895
float: left;
8996
}
9097
}
98+
99+
100+
/* sidebar */
101+
102+
aside {
103+
section.user_info {
104+
margin-top: 20px;
105+
}
106+
section {
107+
padding: 10px 0;
108+
margin-top: 20px;
109+
&:first-child {
110+
border: 0;
111+
padding-top: 0;
112+
}
113+
span {
114+
display: block;
115+
margin-bottom: 3px;
116+
line-height: 1;
117+
}
118+
h1 {
119+
font-size: 1.4em;
120+
text-align: left;
121+
letter-spacing: -1px;
122+
margin-bottom: 3px;
123+
margin-top: 0px;
124+
}
125+
}
126+
}
127+
128+
/* forms */
129+
130+
input, textarea, select, .uneditable-input {
131+
border: 1px solid #bbb;
132+
width: 100%;
133+
margin-bottom: 15px;
134+
@include box_sizing;
135+
}
136+
137+
input {
138+
height: auto !important;
139+
}
140+
141+
#error_explanation {
142+
color: red;
143+
ul {
144+
color: red;
145+
margin: 0 0 30px 0;
146+
}
147+
}
148+
149+
.field_with_errors {
150+
@extend .has-error;
151+
.form-control {
152+
color: $state-danger-text;
153+
}
154+
}

app/controllers/users_controller.rb

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# frozen_string_literal: true
22

33
class UsersController < ApplicationController
4-
def new; end
4+
5+
def new
6+
@user = User.new
7+
end
8+
9+
def show
10+
@user = User.find(params[:id])
11+
end
12+
13+
def create
14+
@user = User.new(user_params)
15+
if @user.save
16+
redirect_to @user
17+
else
18+
render 'new'
19+
end
20+
end
21+
22+
private
23+
24+
def user_params
25+
params.require(:user).permit(:name, :email, :password,
26+
:password_confirmation)
27+
end
528
end

app/views/home_pages/main.html.erb

-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@
55

66
<%= link_to "Sign up now!", signup_path, class: "btn btn-lg btn-primary" %>
77
</div>
8-
9-
<%= link_to image_tag("ruby.png", alt: "Ruby logo") %>

app/views/layouts/_header.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<%= link_to "test project", root_path, id: "logo" %>
44
<nav>
55
<ul class="nav navbar-nav navbar-right">
6+
<%= link_to image_tag("ruby.png", alt: "Ruby logo") %>
67
<li><%= link_to "Home", root_path %></li>
78
<li><%= link_to "Log in", '#' %></li>
89
</ul>
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<% if @user.errors.any? %>
2+
<div id="error_explanation">
3+
<div class="alert alert-danger">
4+
The form contains <%= pluralize(@user.errors.count, "error") %>.
5+
</div>
6+
<ul>
7+
<% @user.errors.full_messages.each do |msg| %>
8+
<li><%= msg %></li>
9+
<% end %>
10+
</ul>
11+
</div>
12+
<% end %>

app/views/users/new.html.erb

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
1-
<h1>Users#new</h1>
2-
<p>Find me in app/views/users/new.html.erb</p>
1+
<% provide(:title, 'Sign up') %>
2+
<h1>Sign up</h1>
3+
4+
<div class="row">
5+
<div class="col-md-6 col-md-offset-3">
6+
<%= form_for(@user) do |f| %>
7+
<%= render 'shared/error_messages' %>
8+
9+
<%= f.label :name %>
10+
<%= f.text_field :name, class: 'form-control' %>
11+
12+
<%= f.label :email %>
13+
<%= f.email_field :email, class: 'form-control' %>
14+
15+
<%= f.label :password %>
16+
<%= f.password_field :password, class: 'form-control' %>
17+
18+
<%= f.label :password_confirmation, "Confirmation" %>
19+
<%= f.password_field :password_confirmation, class: 'form-control' %>
20+
21+
<%= f.submit "Create my account", class: "btn btn-primary" %>
22+
<% end %>
23+
</div>
24+
</div>

app/views/users/show.html.erb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<% provide(:title, @user.name) %>
2+
3+
<div class="row">
4+
<aside class="col-md-4">
5+
<section class="user_info">
6+
<h1>
7+
<%= @user.name %>
8+
</h1>
9+
</section>
10+
</aside>
11+
</div>

config/routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Rails.application.routes.draw do
44
root 'home_pages#main'
55

6-
get '/signup', to: 'users#new'
6+
get 'signup' => 'users#new'
77

88
resources :users
99
end

db/schema.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# frozen_string_literal: true
2-
31
# This file is auto-generated from the current state of the database. Instead
42
# of editing this file, please use the migrations feature of Active Record to
53
# incrementally modify your database, and then regenerate this schema definition.
@@ -12,16 +10,18 @@
1210
#
1311
# It's strongly recommended that you check this file into your version control system.
1412

15-
ActiveRecord::Schema.define(version: 20_191_011_212_619) do
13+
ActiveRecord::Schema.define(version: 2019_10_11_212619) do
14+
1615
# These are extensions that must be enabled in order to support this database
17-
enable_extension 'plpgsql'
16+
enable_extension "plpgsql"
1817

19-
create_table 'users', force: :cascade do |t|
20-
t.string 'name'
21-
t.string 'email'
22-
t.datetime 'created_at', precision: 6, null: false
23-
t.datetime 'updated_at', precision: 6, null: false
24-
t.string 'password_digest'
25-
t.index ['email'], name: 'index_users_on_email', unique: true
18+
create_table "users", force: :cascade do |t|
19+
t.string "name"
20+
t.string "email"
21+
t.datetime "created_at", precision: 6, null: false
22+
t.datetime "updated_at", precision: 6, null: false
23+
t.string "password_digest"
24+
t.index ["email"], name: "index_users_on_email", unique: true
2625
end
26+
2727
end

0 commit comments

Comments
 (0)