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

Commit

Permalink
Add primitive sign-up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS committed Jul 27, 2014
1 parent 8245fee commit 94ea8b1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
class PeopleController < ApplicationController
def new
@person = Person.new
end

def create
@person = Person.new(person_params)

@person.save
redirect_to @person
if @person.save
redirect_to root_url, :notice => "Signed up!"
else
render :new
end
end

def show
Expand All @@ -15,6 +19,6 @@ def show

private
def person_params
params.require(:person).permit(:name)
params.require(:person).permit(:name, :email, :password, :password_confirmation)
end
end
5 changes: 5 additions & 0 deletions app/models/person.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class Person < ActiveRecord::Base
authenticates_with_sorcery!

validates_confirmation_of :password
validates_presence_of :password, :on => :create
validates_presence_of :email
validates_uniqueness_of :email
end
28 changes: 27 additions & 1 deletion app/views/people/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,37 @@

<%= form_for :person, url: people_path do |f| %>
<% if @person.errors.any? %>
<div class="error_messages">
<h2>Form is invalid</h2>
<ul>
<% for message in @person.errors.full_messages %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<p>
<%= f.label :name %><br>
<%= f.text_field :name %>
</p>


<p>
<%= f.label :email %><br>
<%= f.text_field :email %>
</p>

<p>
<%= f.label :password %><br>
<%= f.password_field :password %>
</p>

<p>
<%= f.label :password_confirmation %><br>
<%= f.password_field :password_confirmation %>
</p>

<p>
<%= f.submit %>
</p>
Expand Down

0 comments on commit 94ea8b1

Please sign in to comment.