Why cannot read activation_digest?

10 views
Skip to first unread message

Vaclav Prokop

unread,
Jul 19, 2016, 4:42:53 AM7/19/16
to Ruby on Rails: Talk
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 Doe", email: "joh...@example.com", 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

Frederick Cheung

unread,
Jul 19, 2016, 4:49:59 AM7/19/16
to Ruby on Rails: Talk


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 

Reply all
Reply to author
Forward
0 new messages