-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
198 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,29 @@ | ||
class UsersController < ApplicationController | ||
|
||
def show | ||
@user = User.find(params[:id]) | ||
# debugger | ||
end | ||
|
||
def new | ||
@user = User.new | ||
end | ||
|
||
def create | ||
@user = User.new(user_params) | ||
if @user.save | ||
# Handle a successful 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
module UsersHelper | ||
|
||
# Returns the Gravatar for the given user. | ||
def gravatar_for(user) | ||
gravatar_id = Digest::MD5::hexdigest(user.email.downcase) | ||
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}" | ||
image_tag(gravatar_url, alt: user.name, class: "gravatar") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<% 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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,24 @@ | ||
<% provide(:title, 'Sign up') %> | ||
<h1>Sign up</h1> | ||
<p>This will be a signup page for new users.</p> | ||
|
||
<div class="row"> | ||
<div class="col-md-6 col-md-offset-3"> | ||
<%= form_for(@user) do |f| %> | ||
<%= render 'shared/error_messages' %> | ||
|
||
<%= f.label :name %> | ||
<%= f.text_field :name, class: 'form_control' %> | ||
|
||
<%= f.label :email %> | ||
<%= f.text_field :email, class: 'form_control' %> | ||
|
||
<%= f.label :password %> | ||
<%= f.password_field :password, class: 'form_control' %> | ||
|
||
<%= f.label :password_confirmation, "Confirmation" %> | ||
<%= f.password_field :password_confirmation, class: 'form_control' %> | ||
|
||
<%= f.submit "Create my account", class: "btn btn primary" %> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<% provide(:title, @user.name) %> | ||
<div class="row"> | ||
<aside class="col-md-4"> | ||
<section class="user_info"> | ||
<h1> | ||
<%= gravatar_for @user %> | ||
<%= @user.name %> | ||
</h1> | ||
</section> | ||
</aside> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1466 | ||
4451 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'test_helper' | ||
|
||
class UsersSignupTest < ActionDispatch::IntegrationTest | ||
|
||
# test "the truth" do | ||
test "invalid signup information" do | ||
# assert true | ||
assert_no_difference 'User.count' do | ||
post users_path, user: { name: "", | ||
email: "user@invalid", | ||
password: "foo", | ||
password_confirmation: "bar" } | ||
# end | ||
end | ||
assert_template 'users/new' | ||
end | ||
|
||
test "valid signup information" do | ||
get signup_path | ||
assert_difference 'User.count', 1 do | ||
post_via_redirect users_path, user: { name: "Example User", | ||
email: "[email protected]", | ||
password: "password", | ||
password_confirmation: "password" } | ||
end | ||
assert_template 'users/show' | ||
end | ||
end |