Skip to content

Commit c1ed299

Browse files
committed
Finish user signup
1 parent 5ec6ba6 commit c1ed299

File tree

9 files changed

+181
-8
lines changed

9 files changed

+181
-8
lines changed

app/assets/stylesheets/application.bootstrap.scss

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
@import "bootstrap-icons/font/bootstrap-icons";
33

44
/* mixins, variables, etc. */
5-
$gray: gray;
6-
$gray-light: #777;
75
$gray-medium-light: #eaeaea;
8-
$gray-darker: #555;
6+
7+
@mixin box_sizing {
8+
-moz-box-sizing: border-box;
9+
-webkit-box-sizing: border-box;
10+
box-sizing: border-box;
11+
}
912
/* universal */
1013

1114
body > div {
@@ -45,7 +48,7 @@ h2 {
4548
margin-bottom: 30px;
4649
text-align: center;
4750
font-weight: normal;
48-
color: $gray-light;
51+
color: $gray-600;
4952
}
5053
p {
5154
font-size: 1.1em;
@@ -71,11 +74,11 @@ footer {
7174
margin-top: 45px;
7275
padding-top: 5px;
7376
border-top: 1px solid $gray-medium-light;
74-
color: $gray-light;
77+
color: $gray-600;
7578
a {
76-
color: $gray;
79+
color: $gray-500;
7780
&:hover {
78-
color: $gray-darker;
81+
color: $gray-800;
7982
}
8083
}
8184
small {
@@ -90,3 +93,83 @@ footer {
9093
}
9194
}
9295
}
96+
/* miscellaneous */
97+
.debug_dump {
98+
clear: both;
99+
float: left;
100+
width: 100%;
101+
margin-top: 45px;
102+
}
103+
104+
/* sidebar */
105+
aside {
106+
section.user_info {
107+
margin-top: 20px;
108+
}
109+
section {
110+
padding: 10px 0;
111+
margin-top: 20px;
112+
&:first-child {
113+
border: 0;
114+
padding-top: 0;
115+
}
116+
span {
117+
display: block;
118+
margin-bottom: 3px;
119+
line-height: 1;
120+
}
121+
h1 {
122+
font-size: 1.4em;
123+
text-align: left;
124+
letter-spacing: -1px;
125+
margin-bottom: 3px;
126+
margin-top: 0px;
127+
}
128+
}
129+
}
130+
.gravatar {
131+
float: left;
132+
margin-right: 10px;
133+
}
134+
.gravatar_edit {
135+
margin-top: 15px;
136+
}
137+
/* forms */
138+
input,
139+
textarea,
140+
select,
141+
.uneditable-input {
142+
border: 1px solid #bbb;
143+
width: 100%;
144+
margin-bottom: 15px;
145+
@include box_sizing;
146+
}
147+
input {
148+
height: auto !important;
149+
}
150+
/* forms */
151+
input,
152+
textarea,
153+
select,
154+
.uneditable-input {
155+
border: 1px solid #bbb;
156+
width: 100%;
157+
margin-bottom: 15px;
158+
@include box_sizing;
159+
}
160+
input {
161+
height: auto !important;
162+
}
163+
#error_explanation {
164+
color: red;
165+
ul {
166+
color: red;
167+
margin: 0 0 30px 0;
168+
}
169+
}
170+
.field_with_errors {
171+
@extend .is-invalid;
172+
.form-control {
173+
color: $danger;
174+
}
175+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
class UsersController < ApplicationController
2+
def show
3+
@user = User.find(params[:id])
4+
end
5+
26
def new
7+
@user = User.new
8+
end
9+
10+
def create
11+
@user = User.new(user_params)
12+
if @user.save
13+
flash[:success] = "Welcome to the Sample App!"
14+
redirect_to @user
15+
# Handle a successful save.
16+
else
17+
render "new", status: :unprocessable_entity
18+
end
19+
end
20+
21+
private
22+
23+
def user_params
24+
params.require(:user).permit(:name, :email, :password,
25+
:password_confirmation)
326
end
427
end

app/helpers/users_helper.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
module UsersHelper
2+
# Returns the Gravatar for the given user.
3+
# Returns the Gravatar for the given user.
4+
def gravatar_for(user, size: 80)
5+
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
6+
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
7+
image_tag(gravatar_url, alt: user.name, class: "gravatar")
8+
end
29
end

app/views/layouts/application.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626
<body>
2727
<%= render 'layouts/header' %>
2828
<div class="container">
29+
<% flash.each do |message_type, message| %>
30+
<div class="alert alert-<%= message_type %>"><%= message %></div>
31+
<% end %>
2932
<%= yield %>
3033
<%= render 'layouts/footer' %>
34+
<%= debug(params) if Rails.env.development? %>
3135
</div>
3236
</body>
3337

Lines changed: 12 additions & 0 deletions
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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
<% provide(:title, 'Sign up') %>
22
<h1>Sign up</h1>
3-
<p>This will be a signup page for new users.</p>
3+
<div class="row">
4+
<div class="col-md-6 offset-md-3">
5+
<%= form_with(model: @user) do |f| %>
6+
<%= render 'shared/error_messages' %>
7+
<%= f.label :name %>
8+
<%= f.text_field :name, class: 'form-control' %>
9+
<%= f.label :email %>
10+
<%= f.email_field :email, class: 'form-control' %>
11+
<%= f.label :password %>
12+
<%= f.password_field :password, class: 'form-control' %>
13+
<%= f.label :password_confirmation, "Confirmation" %>
14+
<%= f.password_field :password_confirmation, class: 'form-control' %>
15+
<%= f.submit "Create my account", class: "btn btn-primary" %>
16+
<% end %>
17+
</div>
18+
</div>

app/views/users/show.html.erb

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

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515

1616
# Defines the root path route ("/")
1717
# root "posts#index"
18+
resources :users
1819
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require "test_helper"
2+
3+
class UsersSignupTest < ActionDispatch::IntegrationTest
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
test "invalid signup information" do
8+
assert_no_difference "User.count" do
9+
post users_path, params: { user: { name: "Example User",
10+
11+
password: "password",
12+
password_confirmation: "password" } }
13+
end
14+
follow_redirect!
15+
assert_template "users/show"
16+
end
17+
end

0 commit comments

Comments
 (0)