Skip to content

Commit 01aaacd

Browse files
author
Ryan Bigg
committed
Section 6.3: Implemented sign up
1 parent e791903 commit 01aaacd

File tree

10 files changed

+83
-0
lines changed

10 files changed

+83
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Place all the behaviors and hooks related to the matching controller here.
2+
# All this logic will automatically be available in application.js.
3+
# You can use CoffeeScript in this file: http://coffeescript.org/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place all the styles related to the users controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: http://sass-lang.com/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class UsersController < ApplicationController
2+
def new
3+
@user = User.new
4+
end
5+
6+
def create
7+
@user = User.new(user_params)
8+
9+
if @user.save
10+
flash[:notice] = "You have signed up successfully."
11+
redirect_to projects_path
12+
else
13+
render :new
14+
end
15+
end
16+
17+
def show
18+
end
19+
20+
private
21+
def user_params
22+
params.require(:user).permit(:name,
23+
:email,
24+
:password,
25+
:password_confirmation)
26+
end
27+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module UsersHelper
2+
end

ticketee/app/views/layouts/application.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
<li class='<%= 'active' if current_page?('/') %>'>
2525
<%= link_to "Home", root_path %>
2626
</li>
27+
<li class='<%= 'active' if current_page?('/users/sign_up') %>'>
28+
<%= link_to "Sign up", sign_up_path %>
29+
</li>
2730
</ul>
2831
</div>
2932
</nav>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<%= simple_form_for @user, url: sign_up_path do |f| %>
2+
<% if @user.errors.any? %>
3+
<div id="error_explanation">
4+
<h2><%= pluralize(@user.errors.count, "error") %>
5+
prohibited this user from being saved:</h2>
6+
7+
<ul>
8+
<% @user.errors.full_messages.each do |msg| %>
9+
<li><%= msg %></li>
10+
<% end %>
11+
</ul>
12+
</div>
13+
<% end %>
14+
15+
<%= f.input :name %>
16+
<%= f.input :email %>
17+
<%= f.input :password %>
18+
<%= f.input :password_confirmation %>
19+
20+
<%= f.button :submit, "Sign up", class: "btn-primary" %>
21+
<% end %>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class='row'>
2+
<h2>Sign Up</h2>
3+
4+
<%= render "form" %>
5+
</div>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>Users#show</h1>
2+
<p>Find me in app/views/users/show.html.erb</p>

ticketee/config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Rails.application.routes.draw do
22
root 'projects#index'
3+
get "/users/sign_up", to: "users#new", as: "sign_up"
4+
post "/users/sign_up", to: "users#create"
35

46
resources :projects do
57
resources :tickets
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require "rails_helper"
2+
3+
feature "Signing up" do
4+
scenario "Successful sign up" do
5+
visit "/"
6+
7+
click_link "Sign up"
8+
fill_in "Email", with: "[email protected]"
9+
fill_in "Password", with: "password"
10+
fill_in "Password confirmation", with: "password"
11+
click_button "Sign up"
12+
13+
expect(page).to have_content("You have signed up successfully.")
14+
end
15+
end

0 commit comments

Comments
 (0)