Sorcery 0.7.4をRails 3.1.1で使用して認証します。 パスワードリセットをセットアップしようとするまで、すべてうまくいっていました。Ruby on Rails with SorceryパスワードのEメールをリセットすると、定義されていないメソッドエラーが発生する
アクティベーションは完全に動作し、電子メールが送信されますが、何らかの理由でリセットパスワードメールを送信しようとするとこのエラーが発生します。
undefined method `reset_password_email' for nil:NilClass
私はチュートリアルを正確にコピーしました。コンソールでクイックテストを実行したところ、期待どおりにメールが送信されました。コンソールで:
実際のコントローラでuser = User.find(1)
user.deliver_reset_password_instructions!
、それは電子メールで、ユーザーがフォームから送信され、ログに私はそれが右のユーザーを取得し、トークンを設定されて見ることができます見つけたが、上記のようなエラーが出てロールバックします。
deliver_reset_password_instructionsのgemのコードを確認しました!それが失敗する理由はないようです。
PasswordResetsController:
@user = User.find_by_email(params[:email])
@user.deliver_reset_password_instructions! if @user
以下がGEMコードからコピーされる:
Instance Method in Gem:
def deliver_reset_password_instructions!
config = sorcery_config
# hammering protection
return false if config.reset_password_time_between_emails && self.send(config.reset_password_email_sent_at_attribute_name) && self.send(config.reset_password_email_sent_at_attribute_name) > config.reset_password_time_between_emails.ago.utc
self.send(:"#{config.reset_password_token_attribute_name}=", TemporaryToken.generate_random_token)
self.send(:"#{config.reset_password_token_expires_at_attribute_name}=", Time.now.in_time_zone + config.reset_password_expiration_period) if config.reset_password_expiration_period
self.send(:"#{config.reset_password_email_sent_at_attribute_name}=", Time.now.in_time_zone)
self.class.transaction do
self.save!(:validate => false)
generic_send_email(:reset_password_email_method_name, :reset_password_mailer)
end
end
The method called above for mailing:
def generic_send_email(method, mailer)
config = sorcery_config
mail = config.send(mailer).send(config.send(method),self)
if defined?(ActionMailer) and config.send(mailer).superclass == ActionMailer::Base
mail.deliver
end
end
もう一度必要なすべてのメーラービットとピースが、ワークコンソールからです。
この手順で追加/変更する行を削除/リセットする必要があります:http://marker.to/XZcXYhそしてStefanoのBernardi Answer;で説明されている回避策を適用してください) – Jmlevick