Ruby 爲什麽 securerandom 引入不進來

a1345774000 · 2021年08月25日 · 最后由 a1345774000 回复于 2021年08月25日 · 237 次阅读

這是 client.rb 模板文件

require 'securerandom'
class Client < ApplicationRecord
  validates :client_adress, presence: { message: "メールアドレスを入力" }
  validates :client_adress, format: {with: /\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z/, message: "メールアドレスを入力が正しくありません"}
  def Client.new_token
    SecureRandom_urlsafe_base64
  end
end

這是控制器

def temporary
    if request.post?
      @user = params[:email]
      @user.activation_token = Client.new_token
      MailVerifyMailer.welcome_email(@user).deliver_now
    end  
end  

報錯内容顯示 uninitialized constant #Class:0x00007f02d8297480::SecureRandom_urlsafe_base64 報錯行:SecureRandom_urlsafe_base64

SecureRandom.urlsafe_base64
需要 登录 后方可回复, 如果你还没有账号请 注册新账号