Skip to content

Instantly share code, notes, and snippets.

@waratuman
Created April 13, 2012 18:25
Show Gist options
  • Save waratuman/2378948 to your computer and use it in GitHub Desktop.
Save waratuman/2378948 to your computer and use it in GitHub Desktop.
$ cd ~/src
$ rails new MLS
$ rails generate model user
$ mate db/migrate/20120411200952_create_users.rb
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name, :null => false
t.string :email, :null => false
t.string :phone
t.string :company
t.string :title
t.string :license_id
t.string :linkedin
t.string :twitter
t.string :facebook
t.string :web
t.string :password_digest, :null => false
t.timestamps
end
end
end
$ mate app/models/user.rb
class User < ActiveRecord::Base
attr_accessor :password
attr_protected :password_digest
validates :name, :presence => true
validates :email, :presence => true, :uniqueness => true, :email => true
validates :password, :presence => true, :confirmation => true
validates :password_confirmation, :presence => { :if => :password }
validates :phone, :format => { :allow_nil => true, :with => /^[\(\)0-9\- \+\.]{10,20}\s*[extension\.]{0,9}\s*[0-9]{0,5}$/i }
def password=(pass)
return if pass.blank?
@password = pass
self.password_digest = BCrypt::Password.create(pass)
end
end
$ mate Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.3'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'email_validator'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platform => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment