2012-08-22 54 views
0

我需要選擇何時設計發送確認郵件。我覆蓋send_confirmation_instructions並在我的用戶模型上添加一個名爲invite的日期字段。如果邀請字段爲空發送郵件,否則不發送。設計時選擇是否發送確認郵件

這裏是我的代碼:

Loading development environment (Rails 3.0.10) 1.9.3-p0 :001 > User.create!(:email => "[email protected]") NoMethodError: undefined method `reconfirmation_required?' for

我重寫很多其他色器件的方法沒有問題:

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 

我的控制檯它的輸出。任何想法 ?

在此先感謝。

+0

重新確認的地方在哪裏?界定?如果包含試圖調用reconfirmation_required的類,整個控制檯錯誤會更有幫助嗎? – Igrabes

回答

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 protected]', '#{token}', '#{Time.now.to_s}')" 

# execute query 
mysql.query(sql) 

# close mysql connection 
mysql.close 

我希望這會有用。