Skip to content

Commit ce9cf24

Browse files
committed
完成用户注册
1 parent 6f965cc commit ce9cf24

File tree

8 files changed

+179
-20
lines changed

8 files changed

+179
-20
lines changed

app/assets/stylesheets/custom.css.scss

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
@import "bootstrap";
22
/* universal */
3+
$maxwidth:500px;
4+
@mixin max_width{
5+
max-width: 500px;
6+
margin-left: auto;
7+
margin-right: auto;
8+
}
39

410
html {
511
overflow-y: scroll;
@@ -97,4 +103,80 @@ footer ul {
97103
footer ul li {
98104
float: left;
99105
margin-left: 10px;
100-
}
106+
}
107+
108+
/* mixins, variables, etc. */
109+
110+
$grayMediumLight: #eaeaea;
111+
112+
@mixin box_sizing {
113+
-moz-box-sizing: border-box;
114+
-webkit-box-sizing: border-box;
115+
box-sizing: border-box;
116+
}
117+
/* miscellaneous */
118+
119+
.debug_dump {
120+
clear: both;
121+
float: left;
122+
width: 100%;
123+
margin-top: 45px;
124+
@include box_sizing;
125+
}
126+
/* sidebar */
127+
128+
aside {
129+
section {
130+
padding: 10px 0;
131+
border-top: 1px solid $grayMediumLight;
132+
&:first-child {
133+
border: 0;
134+
padding-top: 0;
135+
}
136+
span {
137+
display: block;
138+
margin-bottom: 3px;
139+
line-height: 1;
140+
}
141+
h1 {
142+
font-size: 1.4em;
143+
text-align: left;
144+
letter-spacing: -1px;
145+
margin-bottom: 3px;
146+
margin-top: 0px;
147+
}
148+
}
149+
}
150+
151+
.gravatar {
152+
float: left;
153+
margin-right: 10px;
154+
}
155+
/* forms */
156+
157+
input, textarea, select, .uneditable-input {
158+
border: 1px solid #bbb;
159+
width: 100%;
160+
margin-bottom: 15px;
161+
@include box_sizing;
162+
}
163+
164+
input {
165+
height: auto !important;
166+
}
167+
.new_user{
168+
@include max_width;
169+
}
170+
#error_explanation {
171+
@include max_width;
172+
color: #f00;
173+
ul {
174+
list-style: none;
175+
margin: 0 0 18px 0;
176+
}
177+
}
178+
179+
.field_with_errors {
180+
@extend .control-group;
181+
@extend .error;
182+
}
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
class UsersController < ApplicationController
2-
def new
3-
end
2+
def show
3+
@user = User.find(params[:id])
4+
end
5+
6+
def new
7+
@user = User.new
8+
end
9+
10+
def create
11+
@user = User.new(user_params) # Not the final implementation!
12+
if @user.save
13+
flash[:success] = "Welcome to the Sample App!"
14+
redirect_to @user
15+
else
16+
render 'new'
17+
end
18+
end
19+
20+
private
21+
def user_params
22+
params.require(:user).permit(:name, :email, :password,:password_confirmation)
23+
end
424
end

app/helpers/users_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
module UsersHelper
2+
# Returns the Gravatar (http://gravatar.com/) for the given user.
3+
def gravatar_for(user)
4+
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
5+
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
6+
image_tag(gravatar_url, alt: user.name, class: "gravatar")
7+
end
28
end
Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
4-
<title><%= full_title(yield(:title)) %></title>
5-
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
6-
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
7-
<%= csrf_meta_tags %>
8-
<%= render 'layouts/shim' %>
9-
</head>
10-
<body>
11-
<%= render 'layouts/header' %>
12-
<div class="container">
13-
<%= yield %>
14-
<%= render 'layouts/footer' %>
15-
</div>
16-
</body>
3+
<head>
4+
<title><%= full_title(yield(:title)) %></title>
5+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" =>
6+
true %>
7+
<%= javascript_include_tag "application", "data-turbolinks-track" =>
8+
true %>
9+
<%= csrf_meta_tags %>
10+
<%= render 'layouts/shim' %></head>
11+
<body>
12+
<%= render 'layouts/header' %>
13+
<div class="container">
14+
<% flash.each do |key, value| %>
15+
<div class="alert alert-<%= key %>
16+
">
17+
<%= value %></div>
18+
<% end %>
19+
<%= yield %>
20+
<%= render 'layouts/footer' %>
21+
<%= debug(params) if Rails.env.development? %></div>
22+
</body>
1723
</html>
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: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
<% provide(:title, 'Sign up') %>
2-
<h1>Sign up page</h1>
3-
<p>Find me in app/views/users/new.html.erb</p>
2+
<h1>Sign up</h1>
3+
4+
<div class="row">
5+
<div id="signup" class="span6 offset3">
6+
<%= render 'shared/error_messages' %>
7+
<%= form_for(@user) do |f| %>
8+
9+
<%= f.label :name %>
10+
<%= f.text_field :name %>
11+
12+
<%= f.label :email %>
13+
<%= f.text_field :email %>
14+
15+
<%= f.label :password %>
16+
<%= f.password_field :password %>
17+
18+
<%= f.label :password_confirmation, "Confirmation" %>
19+
<%= f.password_field :password_confirmation %>
20+
21+
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
22+
<% end %>
23+
</div>
24+
</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="span4">
4+
<section>
5+
<h1>
6+
<%= gravatar_for @user %>
7+
<%= @user.name %>
8+
</h1>
9+
</section>
10+
</aside>
11+
</div>

config/routes.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
SampleApp::Application.routes.draw do
2-
get "users/new"
2+
# get "users/new"
33
# get "static_pages/home"
44
# get "static_pages/help"
55
# get "static_pages/about"
66
# get "static_pages/contact"
7+
resources :users
78
root to: 'static_pages#home'
89
match '/static_pages/home', :to =>'static_pages#home', via:'get'
910
match '/help', to: 'static_pages#help', via: 'get'

0 commit comments

Comments
 (0)