在devise rails 3应用程序的用户注册后发送一个actionmailer电子邮件 [英] Send an actionmailer email upon user registration in devise rails 3 application
问题描述
我正在使用使用devise宝石的rails 3应用程序在用户注册后发送电子邮件。每次尝试发送电子邮件时,我会收到以下错误:
I'm trying to send an email upon user registration in a rails 3 application that is using the devise gem. Every time I try to the send the email I get the following error:
Devise中的NoMethodError :: RegistrationsController#为UserMailer创建
undefined方法`welcome_email' Class
NoMethodError in Devise::RegistrationsController#create undefined method `welcome_email' for UserMailer:Class
我的app / model / user.rb具有以下代码...
My app/model/user.rb has the following code...
after_create :send_welcome_email
def send_welcome_email
UserMailer.welcome_email(self).deliver
end
我的应用/ mailers / user_mailer.rb具有以下代码...
My app/mailers/user_mailer.rb has the following code...
class UserMailer < ActionMailer::Base
default from: "support@mysite.com"
def welcome_email(user)
@user = user
@url = "http://mysite.com/login"
mail(:to => "#{user.email}", :subject => "Welcome to My Awesome Site")
end
end
方法welcome_email存在,所以我不知道为什么我得到错误。在过去几个小时内尝试解决这个问题。
The method welcome_email exists so I'm not sure why I'm getting the error. Been trying to resolve this problem for the past couple of hours.
提前感谢您的帮助!像往常一样,如果你给我一个很好的答案,我会接受它。
Alex
Thanks in advance for you help!! As always if you give me a good answer I will accept it as so. Alex
推荐答案
看起来像 welcome_email
是一个实例方法。而且看起来错误说它需要是一个类的方法。所以尝试将方法声明重写为:
Looks like the welcome_email
is an instance method. And it looks like the error says it needs to be a class method. So try rewriting the method declaration as:
def self.welcome_email(user)
def self.welcome_email(user)
我想应该解决它。
这篇关于在devise rails 3应用程序的用户注册后发送一个actionmailer电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!