我希望 Recoverable 模块为我的用户发送带有重置密码链接的“邀请”电子邮件(该应用程序仅在邀请中),我在初始化程序中部分声明了方法:
module Devise
class Mailer
def invite_new_user(record)
devise_mail(record, :invitation_instructions)
end
end
end
module Devise
module Models
module Recoverable
def send_invite_user_instructions!
return unless status == User::STATUS_PENDING
generate_reset_password_token!
::Devise.mailer.invite_new_user(self).deliver
end
end
end
end
并且可恢复的扩展得很好,但它说我的邮件程序没有邀请新用户方法(rails 控制台输出):
1.9.2p290 :002 > user.send_invite_user_instructions!
User Load (1.4ms) SELECT "users".* FROM "users" WHERE "users"."reset_password_token" = 'zMQK1CEXYupjNKpH8dph' LIMIT 1
(0.3ms) BEGIN
(15.0ms) UPDATE "users" SET "reset_password_token" = 'zMQK1CEXYupjNKpH8dph', "updated_at" = '2012-05-01 17:40:32.085256' WHERE "users"."id" = 59
(4.5ms) COMMIT
NoMethodError: undefined method `invite_new_user' for Devise::Mailer:Class
但在同一个控制台会话中调用有方法:
1.9.2p290 :003 > ::Devise.mailer.method_defined? 'invite_new_user'
=> true
我错过了什么?