开发者

Railscasts, where 'token' variable comes from

开发者 https://www.devze.com 2023-02-08 00:27 出处:网络
The open source project railscasts has User model (link to the full file) class User < ActiveRecord::Base

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

精彩评论

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

关注公众号