Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finish user signup

  • Loading branch information...
commit decc821d50b38aba8100a1aafd52d61245bdf470 1 parent 99f419b
@Milhouse authored
View
69 app/assets/stylesheets/layout.css.scss
@@ -113,4 +113,73 @@ footer {
nav {
float: none;
}
+}
+
+/* User show page */
+
+table.profile {
+ width: 100%;
+ margin-bottom: 0;
+
+ img.gravatar {
+ border: 1px solid #999;
+ margin-bottom: -15px;
+ }
+}
+
+td.main {
+ width: 70%;
+ padding: 1em;
+}
+
+td.sidebar {
+ width: 30%;
+ padding: 1em;
+ vertical-align: top;
+ background: #ffc;
+}
+
+div.field, div.actions {
+ margin-bottom: 10px;
+}
+
+.field_with_errors {
+ margin-top: 10px;
+ padding: 2px;
+ background-color: red;
+ display: table;
+
+ label {
+ color: #fff;
+ }
+}
+
+#error_explanation {
+ width: 400px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 12px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ background-color: #c00;
+ color: #fff;
+ }
+
+ p {
+ color: #333;
+ margin-bottom: 0;
+ padding: 5px;
+ }
+
+ ul li {
+ font-size: 12px;
+ list-style: square;
+ }
}
View
15 app/controllers/users_controller.rb
@@ -1,4 +1,19 @@
class UsersController < ApplicationController
+ def show
+ @user = User.find(params[:id])
+ end
+
def new
+ @user = User.new
+ end
+
+ def create
+ @user = User.new(params[:user])
+ if @user.save
+ flash[:success] = "Welcome to the Sample App!"
+ redirect_to @user
+ else
+ render 'new'
+ end
end
end
View
6 app/helpers/users_helper.rb
@@ -1,2 +1,8 @@
module UsersHelper
+ # Returns the Gravatar (http://gravatar.com/) for the given user.
+ def gravatar_for(user)
+ gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
+ gravatar_url = "http://gravatar.com/avatar/#{gravatar_id}.png"
+ image_tag(gravatar_url, alt: user.name, class: "gravatar")
+ end
end
View
6 app/views/layouts/application.html.erb
@@ -8,11 +8,15 @@
</head>
<body>
<div class="container">
- <%= render 'layouts/header' %>
+ <%= render 'layouts/header' %>
<section class="round">
+ <% flash.each do |key, value| %>
+ <div class="flash <%= key %>"><%= value %></div>
+ <% end %>
<%= yield %>
</section>
<%= render 'layouts/footer' %>
+ <%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>
View
12 app/views/shared/_error_messages.html.erb
@@ -0,0 +1,12 @@
+<% if @user.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@user.errors.count, "error") %>
+ prohibited this user from being saved:</h2>
+ <p>There were problems with the following fields:</p>
+ <ul>
+ <% @user.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+<% end %>
View
25 app/views/users/new.html.erb
@@ -1,4 +1,25 @@
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
-<p>Find me in app/views/users/new.html.erb</p><h1>Users#new</h1>
-<p>Find me in app/views/users/new.html.erb</p>
+
+<%= form_for(@user) do |f| %>
+ <%= render 'shared/error_messages' %>
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :email %><br />
+ <%= f.text_field :email %>
+ </div>
+ <div class="field">
+ <%= f.label :password %><br />
+ <%= f.password_field :password %>
+ </div>
+ <div class="field">
+ <%= f.label :password_confirmation, "Confirmation" %><br />
+ <%= f.password_field :password_confirmation %>
+ </div>
+ <div class="actions">
+ <%= f.submit "Sign up" %>
+ </div>
+<% end %>
View
15 app/views/users/show.html.erb
@@ -0,0 +1,15 @@
+<% provide :title, @user.name %>
+<table class="profile">
+ <tr>
+ <td class="main">
+ <h1>
+ <%= gravatar_for @user %>
+ <%= @user.name %>
+ </h1>
+ </td>
+ <td class="sidebar round">
+ <strong>Name</strong> <%= @user.name %><br />
+ <strong>URL</strong> <%= link_to user_path(@user), @user %>
+ </td>
+ </tr>
+</table>
View
2  config/routes.rb
@@ -1,5 +1,5 @@
SampleApp::Application.routes.draw do
- get "users/new"
+ resources :users
match '/signup', to: 'users#new'
Please sign in to comment.
Something went wrong with that request. Please try again.