Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
ThaiMinhPhuc_training
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
phuctmZigexn
ThaiMinhPhuc_training
Commits
578550bb
Commit
578550bb
authored
Aug 03, 2018
by
phuctmZigexn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish user signup
parent
38025573
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
78 additions
and
8 deletions
+78
-8
app/assets/stylesheets/custom.scss
+16
-0
app/controllers/users_controller.rb
+8
-2
app/views/layouts/application.html.erb
+5
-0
app/views/shared/_error_messages.html.erb
+13
-0
app/views/users/new.html.erb
+7
-5
config/routes.rb
+1
-1
test/integration/users_signup_test.rb
+28
-0
No files found.
app/assets/stylesheets/custom.scss
View file @
578550bb
...
...
@@ -155,3 +155,18 @@ input, textarea, select, .uneditable-input {
input
{
height
:
auto
!
important
;
}
#error_explanation
{
color
:
red
;
ul
{
color
:
red
;
margin
:
0
0
30px
0
;
}
}
.field_with_errors
{
@extend
.has-error
;
.form-control
{
color
:
$state-danger-text
;
}
}
\ No newline at end of file
app/controllers/users_controller.rb
View file @
578550bb
...
...
@@ -9,11 +9,17 @@ class UsersController < ApplicationController
end
def
create
@user
=
User
.
new
(
params
[
:user
]
)
@user
=
User
.
new
(
user_params
)
if
@user
.
save
flash
[
:success
]
=
"Welcome to the Sample App!"
redirect_to
@user
else
render
'new'
end
end
private
def
user_params
params
.
require
(
:user
).
permit
(
:name
,
:email
,
:password
,
:password_confirmation
)
end
end
app/views/layouts/application.html.erb
View file @
578550bb
...
...
@@ -12,6 +12,11 @@
<body>
<%=
render
'layouts/header'
%>
<div
class=
"container"
>
<%
flash
.
each
do
|
message_type
,
message
|
%>
<div
class=
"alert alert-
<%=
message_type
%>
"
>
<%=
message
%>
</div>
<%
end
%>
<%=
yield
%>
<%=
render
'layouts/footer'
%>
<%=
debug
(
params
)
if
Rails
.
env
.
development?
%>
<!-- display debug information about each page -->
...
...
app/views/shared/_error_messages.html.erb
0 → 100644
View file @
578550bb
<%
if
@user
.
errors
.
any?
%>
<div
id=
"error_explanation"
>
<div
class=
"alert alert-danger"
>
The form contains
<%=
pluralize
(
@user
.
errors
.
count
,
"error"
)
%>
.
</div>
<ul>
<%
@user
.
errors
.
full_messages
.
each
do
|
msg
|
%>
<li>
<%=
msg
%>
</li>
<%
end
%>
</ul>
</div>
<%
end
%>
\ No newline at end of file
app/views/users/new.html.erb
View file @
578550bb
...
...
@@ -3,18 +3,20 @@
<div
class=
"row"
>
<div
class=
"col-md-6 col-md-offet-3"
>
<%=
form_for
@user
do
|
f
|
%>
<%=
form_for
@user
,
url:
signup_path
do
|
f
|
%>
<%=
render
'shared/error_messages'
%>
<%=
f
.
label
:name
%>
<%=
f
.
text_field
:name
%>
<%=
f
.
text_field
:name
,
class:
'form-control'
%>
<%=
f
.
label
:email
%>
<%=
f
.
email_field
:email
%>
<%=
f
.
email_field
:email
,
class:
'form-control'
%>
<%=
f
.
label
:password
%>
<%=
f
.
password_field
:password
%>
<%=
f
.
password_field
:password
,
class:
'form-control'
%>
<%=
f
.
label
:password_confirmation
,
"Confirmation"
%>
<%=
f
.
password_field
:password_confirmation
%>
<%=
f
.
password_field
:password_confirmation
,
class:
'form-control'
%>
<%=
f
.
submit
"Create my account"
,
class:
"btn btn-primary"
%>
<%
end
%>
...
...
config/routes.rb
View file @
578550bb
...
...
@@ -4,6 +4,6 @@ Rails.application.routes.draw do
get
'/about'
,
to:
'static_pages#about'
get
'/contact'
,
to:
'static_pages#contact'
get
'/signup'
,
to:
'users#new'
post
'/signup'
,
to:
'users#create'
resources
:users
end
test/integration/users_signup_test.rb
0 → 100644
View file @
578550bb
require
'test_helper'
class
UsersSignupTest
<
ActionDispatch
::
IntegrationTest
test
"invalid signup information"
do
get
signup_path
assert_no_difference
'User.count'
do
post
users_path
,
params:
{
user:
{
name:
""
,
email:
"user@invalid"
,
password:
"foo"
,
password_confirmation:
"bar"
}
}
end
assert_template
'users/new'
assert_select
'div#<CSS id for error explanation>'
assert_select
'div.<CSS class for field with error>'
end
test
"valid signup information"
do
get
signup_path
assert_difference
'User.count'
,
1
do
post
users_path
,
params:
{
user:
{
name:
"Example User"
,
email:
"user@example.com"
,
password:
"password"
,
password_confirmation:
"password"
}
}
end
follow_redirect!
assert_template
'users/show'
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment