Created
August 9, 2011 08:16
-
-
Save azuby/1133594 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
user views: | |
NEW ACTION | |
<section> | |
<article class="content"> | |
<h1>Sign Up</h1> | |
<%= form_for(@user) do |f| %> | |
<%= render 'shared/error_messages' %> | |
<div class="field"> | |
<%= f.label :first_name, "First Name:" %><br /> | |
<%= f.text_field :first_name %> | |
</div> | |
<div class="field"> | |
<%= f.label :last_name, "Last Name:" %><br /> | |
<%= f.text_field :last_name %> | |
</div> | |
<div class="field"> | |
<%= f.label :email, "Email:" %><br /> | |
<%= f.text_field :email %> | |
</div> | |
<div class="field"> | |
<%= f.label :password, "Password:" %><br /> | |
<%= f.password_field :password %> | |
</div> | |
<div class="field"> | |
<%= f.label :password_confirmation, "Confirm Password" %><br /> | |
<%= f.password_field :password_confirmation %> | |
</div> | |
<div class="actions"> | |
<%= f.submit "Sign up" %> | |
</div> | |
<% end %> | |
</article | |
</section> | |
SHOW ACTION | |
<section> | |
<h1>Users#show</h1> | |
<p>Find me in app/views/users/show.html.erb</p> | |
<tr> | |
<td> | |
<h1> | |
<%= @user.name %>, <%= @user.email %> | |
</h1> | |
</td> | |
<td> | |
<strong>URL:</strong> <%= link_to user_path(@user), @user %> | |
</td> | |
</tr> | |
</section> | |
user controller: | |
class UsersController < ApplicationController | |
def new | |
@user = User.new | |
@title = "Sign Up" | |
end | |
def create | |
@user = User.new(params[:user]) | |
if @user.save | |
flash[:success] = "Welcome to SyncIn!" | |
redirect_to @user | |
else | |
@title = "Sign Up" | |
render 'new' | |
end | |
end | |
def show | |
@user = User.find(params[:id]) | |
@title = @user.name | |
end | |
end | |
user model: | |
# == Schema Information | |
# | |
# Table name: users | |
# | |
# id :integer not null, primary key | |
# first_name :string(255) | |
# last_name :string(255) | |
# email :string(255) | |
# password_digest :string(255) | |
# created_at :datetime | |
# updated_at :datetime | |
# | |
class User < ActiveRecord::Base | |
has_secure_password | |
attr_accessible :first_name, :last_name, :email, :password, :password_confirmation | |
def name | |
self.first_name + " " + self.last_name | |
end | |
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i | |
validates :first_name, :presence => true, | |
:length => { :maximum => 50 } | |
validates :last_name, :presence => true, | |
:length => { :maximum => 50 } | |
validates :email, :presence => true, | |
:format => { :with => email_regex }, | |
:uniqueness => { :case_sensitive => false} | |
validates :password, :presence => true, | |
:length => { :within => 6..40 } | |
end | |
migration: | |
class CreateUsers < ActiveRecord::Migration | |
def self.up | |
create_table :users do |t| | |
t.string :first_name | |
t.string :last_name | |
t.string :email | |
t.string :password_digest | |
t.timestamps | |
end | |
add_index :users, :email, :unique => true | |
end | |
def self.down | |
drop_table :users | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment