Skip to content
This repository was archived by the owner on Mar 9, 2020. It is now read-only.

Commit 94ea8b1

Browse files
committed
Add primitive sign-up code.
1 parent 8245fee commit 94ea8b1

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
class PeopleController < ApplicationController
22
def new
3+
@person = Person.new
34
end
45

56
def create
67
@person = Person.new(person_params)
78

8-
@person.save
9-
redirect_to @person
9+
if @person.save
10+
redirect_to root_url, :notice => "Signed up!"
11+
else
12+
render :new
13+
end
1014
end
1115

1216
def show
@@ -15,6 +19,6 @@ def show
1519

1620
private
1721
def person_params
18-
params.require(:person).permit(:name)
22+
params.require(:person).permit(:name, :email, :password, :password_confirmation)
1923
end
2024
end

app/models/person.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
class Person < ActiveRecord::Base
22
authenticates_with_sorcery!
3+
4+
validates_confirmation_of :password
5+
validates_presence_of :password, :on => :create
6+
validates_presence_of :email
7+
validates_uniqueness_of :email
38
end

app/views/people/new.html.erb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,37 @@
22

33
<%= form_for :person, url: people_path do |f| %>
44

5+
<% if @person.errors.any? %>
6+
<div class="error_messages">
7+
<h2>Form is invalid</h2>
8+
<ul>
9+
<% for message in @person.errors.full_messages %>
10+
<li><%= message %></li>
11+
<% end %>
12+
</ul>
13+
</div>
14+
<% end %>
15+
516
<p>
617
<%= f.label :name %><br>
718
<%= f.text_field :name %>
819
</p>
9-
20+
21+
<p>
22+
<%= f.label :email %><br>
23+
<%= f.text_field :email %>
24+
</p>
25+
26+
<p>
27+
<%= f.label :password %><br>
28+
<%= f.password_field :password %>
29+
</p>
30+
31+
<p>
32+
<%= f.label :password_confirmation %><br>
33+
<%= f.password_field :password_confirmation %>
34+
</p>
35+
1036
<p>
1137
<%= f.submit %>
1238
</p>

0 commit comments

Comments
 (0)