Why cannot read activation_digest?

Hi,
I am excersising RailsTutorial and do not understand why I cannot read
user’s activation_digest although I defined attr_reader for it as such:

attr_reader :activation_digest

activation digest is generated in create_automation_digest method that
is
called during object creation because it is hooked as such:

before_create :create_activation_digest

When I create user in rails console, and save him, I am able to see
activation_digest token in user’s inspect:

2.2.1 :008 > user
=> #<User id: 1, name: “John D.”, email: “[email protected]”,
created_at: “2016-07-19 08:11:05”, updated_at: “2016-07-19 08:11:05”,
password_digest:
“$2a$10$gx2kggc3uP/DJRnII0f9H.vfoxF34j80Odkn.8i5ECt…”,
remember_digest: nil, admin: false, activation_digest:
“$2a$10$Iy1ClXr6qqJBp8DdmxazkuccE6842kj5EieoRerR4mS…”, activated:
false,
activated_at: nil>

However, when I try to read activation_digest using accessor, I get nil:

2.2.1 :009 > user.activation_digest
=> nil

Could someone explain why I cannot read the activation_digest?

Thanks
Vaclav

On Tuesday, July 19, 2016 at 9:42:53 AM UTC+1, Vaclav Prokop wrote:

Hi,
I am excersising RailsTutorial and do not understand why I cannot read
user’s activation_digest although I defined attr_reader for it as such:

attr_reader :activation_digest

This replaces the active record provided method with one that returns
@activation_digest. The attributes from your database table aren’t
stored
in individual instance variables, so this accessor doesn’t work. You
don’t
need to add accessors for columns in the database.

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs