开发者

Railscasts, where 'token' variable comes from

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜