0

我需要选择何时发送确认邮件。我覆盖了 send_confirmation_instructions 并在我的用户模型上添加了一个名为邀请的日期字段。如果受邀字段为空,则发送邮件,否则不发送。

这是我的代码:

  def send_confirmation_instructions
    unless invited.nil?
      self.confirmation_token = nil if reconfirmation_required?
      @reconfirmation_required = false
      generate_confirmation_token! if self.confirmation_token.blank?
    else
      self.confirmation_token = nil if reconfirmation_required?
      @reconfirmation_required = false
      generate_confirmation_token! if self.confirmation_token.blank?
      self.devise_mailer.confirmation_instructions(self).deliver
    end
  end

我的控制台的输出是:

加载开发环境 (Rails 3.0.10) 1.9.3-p0 :001 > User.create!(:email => "hello@test.com") NoMethodError: undefined method `reconfirmation_required?' 为了

我已经重写了许多其他设计方法而没有问题。任何想法 ?

提前致谢。

4

1 回答 1

0

最好的解决方案是手动连接到数据库并将字段添加到用户表中。

# read configuration from database.yml
config = Rails.application.config.database_configuration[Rails.env]
host = config["host"]
database = config["database"]
username = config["username"]
password = config["password"]

# stablish db connection
mysql = Mysql2::Client.new(:host => host, :username => username, :database => database, :password => password)

# generate devise confirmation token
token = (Digest::MD5.hexdigest "#{ActiveSupport::SecureRandom.hex(10)}-#{DateTime.now.to_s}")

# made the sql
sql = "INSERT INTO users (email, confirmation_token, confirmation_sent_at) VALUES ('email@test.com', '#{token}', '#{Time.now.to_s}')"

# execute query
mysql.query(sql)

# close mysql connection
mysql.close

我希望这会有用。

于 2012-08-23T15:20:16.333 回答