【问题标题】:Rails 3: ActionMailerRails 3:动作邮件程序
【发布时间】:2011-05-11 17:32:02
【问题描述】:

我在这里关注this Railscast,从我的 Rails 应用程序发送邮件。

起初我尝试像教程中那样设置邮件拦截器,但我已经放弃了,因为我总是有一个可爱的can't convert nil into Hash (TypeError)

现在我省略了拦截器,我想实际发送一封邮件,但你猜怎么着 - 我的老朋友回来了:

can't convert nil into Hash (TypeError)

app/mailers/user_mailer.rb:20:in `registration'

这是 mailer 类(第 20 行是调用 mail 的类):

class UserMailer < ActionMailer::Base

  def registration( user )
    @invited = user

    subject = 'Welcome!'

    if Rails.env.development?
      to = 'my.private@email.com'
      subject = "to #{@invited.email}: #{subject}"
    else
      to = @invited.email   
    end

    logger.info "Sending email to #{to} with subject #{subject}"

    mail( :from => 'noreply@mysite.com', :to => to, :subject => subject )
  end
end

日志显示:

invite entered for user foo@bar.com
Sending email to foo@bar.com
Sending email to my.private@email.com with subject to foo@bar.com: Welcome!

这是请求的视图文件 (registration.text.erb):

Welcome!

blablah blah click the following link to activate blah blah <%= activate_user_path( @invited )%> blah blah.
blah blah this is actually german (but plaintext) encoded in utf-8. 

Viel Vergnügen beim Verwenden des Systems!

感谢任何帮助

【问题讨论】:

  • 我认为你的usernil
  • #20 是调用 mail(...) 的那个
  • nope user is not nil here, log 实际上显示了正确的数据。
  • 你是如何从控制器调用registration 方法的?
  • 控制器在用户对象上调用invite(),它会执行一些用户操作,然后调用UserMailer.registration( self ).deliver

标签: ruby-on-rails-3 actionmailer


【解决方案1】:

做到了,我在 actionmailer 的配置中有错误

【讨论】:

  • 我被同样的错误困扰了一段时间。如果你还记得的话,你能说说你的错误是什么吗?
猜你喜欢
  • 1970-01-01
  • 2011-08-22
  • 1970-01-01
  • 2014-11-09
  • 2012-11-22
  • 2012-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多