Railscasts,'token'变量来自

时间:2011-02-02 22:53:13

标签: ruby-on-rails-3 railscasts

开源项目railscasts具有用户模型(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

请解释变量token的来源?这个变量的定义在哪里?

1 个答案:

答案 0 :(得分:2)

这是指User模型正在包装的users表的标记列。它在抽象表模式时由ActiveRecord自动定义。