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?
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.
精彩评论