Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create_table "users", :force => true do |t|
- t.string "email"
- t.string "password_hash"
- t.string "password_salt"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
- attr_accessible :email, :password, :password_confirmation
- attr_accessor :password
- before_save :encrypt_password
- validates_confirmation_of :password
- validates_presence_of :password, :on => :create
- validates_presence_of :email
- validates_uniqueness_of :email
- .
- .
- .
- user = User.new
- user.password # => no method error
- user = User.new
- user.email # => nil
- user = User.new
- user.password_confirmation # => nil
- validates_confirmation_of :password
- class User
- attr_accessor :password
- end
- u = User.new
- u.password = "secret"
- u.password # => "secret"
- class Account < ActiveRecord::Base
- # First, you define 2 attributes: "password" and "created_at"
- attr_accessor :password
- attr_accessor :created_at
- # Now you say that you want "password" attribute
- # to be changeable via mass-assignment, while making
- # "created_at" to be non-changeable via mass-assignment
- attr_accessible :password
- end
- a = Account.new
- # Perform mass-assignment (which is usually done when you update
- # your model using the attributes submitted via a web form)
- a.update_attributes(:password => "secret", :created_at => Time.now)
- a.password # => "secret"
- # "password" is changed
- a.created_at # => nil
- # "created_at" remains not changed
- a.created_at = Time.now
- a.created_at # => 2012-09-16 10:03:14
Add Comment
Please, Sign In to add comment