Railscasts, where 'token' variable comes from

142 Views Asked by At

The open source project railscasts has User model (link to the full file)

class User < ActiveRecord::Base
  ........

  def generate_token
    if token.blank? # where's definition of this variable?
      characters = ('a'..'z').to_a + ('A'..'Z').to_a + ('1'..'9').to_a
      begin
        self.token = Array.new(32) { characters.sample }.join
      end while self.class.exists?(:token => token)
    end
  end
end

Please explain me where the variable token came from? Where's the definition of this variable?

1

There are 1 best solutions below

3
On BEST ANSWER

This is referring to the token column for the users table that the User model is wrapping. It is defined by ActiveRecord automatically when abstracting the table schema.