0

いつデバイスが確認メールを送信するかを選択する必要があります。send_confirmation_instructionsを上書きし、ユーザーモデルにinvitedという名前の日付フィールドを追加します。招待フィールドがnullの場合はメールを送信し、そうでない場合は送信されません。

これが私のコードです:

  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:未定義のメソッド `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 に答える