I am going though the tutorial (which I must say is a excellent resource) and I don't quite understand the following:
In section 6.3.1 we create a password_digest column in the db via the creating and running a migration script via :
rails generate migration add_password_digest_to_users password_digest:string
bundle exec rake db:migrate
bundle exec rake db:test:prepare
bundle exec rspec spec/
Then on the rails console I am able to instantiate a user model object and set password_digest on it :
irb(main):007:0> @user = User.new
=> #<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil, password_digest: nil>
irb(main):008:0> @user.password_digest = "zzzz" => "zzzz"
irb(main):009:0> @user.password_digest => "zzzz"
However I can not see a password_digest property on the User model class definition :
class User < ActiveRecord::Base
attr_accessible :email, :name
before_save { |user| user.email = email.downcase}
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :name, presence: true, length: {maximum: 50}
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX}, uniqueness: {case_sensitive: false}
end
I imagine Rails is doing some magic under the covers, would someone mind explaining exactly what it's doing?
Thanks!