Rails:设计:确认后错误

时间:2012-06-04 21:26:32

标签: ruby-on-rails devise confirmation-email

我尝试在用户确认后向活动管理员发送电子邮件。

请参阅:Rails: Devise: Sending an email after user comfirms registration

我写了一个EventMailer类,如下所示:

class EventMailer < ActionMailer::Base
  @user = User

  @host_name = "localhost:3000" if Rails.env.development?
  @host_name = "test.com" if Rails.env.test?
  @host_name = "production.com" if Rails.env.production?

 def self.send_email_to_admin
   @@smtp_settings = { #override default smtp settings since I'm using a difference sender
     :address => "smtp.gmail.com",
     :port => 587,
     :domain => @host_name,

     :authentication => "plain",
     :enable_starttls_auto_=> true,
     :user_name => ENV["ORG_FROM"],
     :password => ENV["ORG_FROM_PWD"],
     :to => ADMIN_RECIPIENTS
     #ADMIN_RECIPIENTS is defined elsewhere
   }
   mail(:subject => "Invite request received from " + @user.first.to_s + " " + @user.last.to_s)
 end
end

当用户注册时,他们会收到注册链接。当他们点击该链接时,会收到以下错误消息:

undefined method `mail' for EventMailer:Class

app/mailers/event_mailer.rb:20:in `send_email_to_admin'
app/controllers/confirmations_controller.rb:11:in `show'

有什么想法吗?

编辑:

解决方案是从邮件nethod

中移动:to和:

1 个答案:

答案 0 :(得分:0)

尝试将:to => DENT_ADMIN_RECIPIENTS移到邮件方法中:

mail(:to => DENT_ADMIN_RECIPIENTS, :subject => "Invite request received from " + @user.first.to_s + " " + @user.last.to_s)