Permalink
Browse files

started User model

  • Loading branch information...
1 parent 6d88315 commit c1ad54264a45320e3a1a2b4e97c01154e16065fb @loarie committed Feb 13, 2012
@@ -1,6 +1,11 @@
class UsersController < ApplicationController
+ def show
+ @user = User.find(params[:id])
+ end
+
def new
+ @title = "Sign up"
end
end
View
@@ -1,2 +1,21 @@
+# == Schema Information
+#
+# Table name: users
+#
+# id :integer not null, primary key
+# name :string(255)
+# email :string(255)
+# created_at :datetime
+# updated_at :datetime
+#
+
class User < ActiveRecord::Base
+ attr_accessible :name, :email
+
+ EmailRegex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
+
+ validates_presence_of :name, :email
+ validates_length_of :name, :maximum => 50
+ validates_format_of :email, :with => EmailRegex
+ validates_uniqueness_of :email, :case_sensitive => false
end
@@ -12,6 +12,7 @@
<%= yield %>
</div>
<%= render 'layouts/footer' %>
+ <%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>
@@ -0,0 +1 @@
+<%= @user.name %>, <%= @user.email %>
View
@@ -10,7 +10,8 @@
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
- # map.resources :products
+ map.resources :users
+
# Sample resource route with options:
# map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
@@ -46,4 +47,5 @@
map.help '/help', :controller => 'pages', :action => 'help'
map.signup '/signup', :controller => 'users', :action => 'new'
+
end
@@ -0,0 +1,9 @@
+class AddEmailUniquenessIndex < ActiveRecord::Migration
+ def self.up
+ add_index :users, :email, :unique => true
+ end
+
+ def self.down
+ remove_index :users, :email
+ end
+end
View
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120213183242) do
+ActiveRecord::Schema.define(:version => 20120213185338) do
create_table "users", :force => true do |t|
t.string "name"
@@ -18,4 +18,6 @@
t.datetime "updated_at"
end
+ add_index "users", ["email"], :name => "index_users_on_email", :unique => true
+
end
View
@@ -1,3 +1,14 @@
+# == Schema Information
+#
+# Table name: users
+#
+# id :integer not null, primary key
+# name :string(255)
+# email :string(255)
+# created_at :datetime
+# updated_at :datetime
+#
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
one:
View
@@ -1,3 +1,14 @@
+# == Schema Information
+#
+# Table name: users
+#
+# id :integer not null, primary key
+# name :string(255)
+# email :string(255)
+# created_at :datetime
+# updated_at :datetime
+#
+
require 'test_helper'
class UserTest < ActiveSupport::TestCase

0 comments on commit c1ad542

Please sign in to comment.