【问题标题】:Rails 3 Overriding Devise MailerRails 3 重写设计邮件程序
【发布时间】:2012-11-22 09:11:13
【问题描述】:

我正在开发一个与 Mandrill(MailChimp 的事务性电子邮件服务)紧密集成的应用程序,我正在尝试覆盖 Devise Mailer,但由于某种原因,当我向 Mandrill 发送 API 调用时,我收到了他们的电子邮件,但 Devise 也给我发了一封电子邮件(这是空白的)。

这是我的DeviseMailer

class MyDeviseMailer < Devise::Mailer
  def reset_password_instructions(record)
    mandrill = Mandrill::API.new("#{MandrillConfig.api_key}")
    mandrill.messages 'send-template',
            { 
              :template_name => 'Forgot Password', 
              :template_content => "",
              :message => {
                :subject => "Forgot Password",
                :from_email => "test@test123.com",
                :from_name => "Company Support",
                :to => [
                  {
                    :email => record.email
                  }
                ],
                :global_merge_vars => [
                  {
                    :name => "FIRST_NAME",
                    :content => record.first_name
                  },
                  {
                    :name => "FORGOT_PASSWORD_URL",
                    :content => "<a href='#{edit_user_password_url(:reset_password_token => record.reset_password_token)}'>Change My Password</a>"
                  }
                ]
              }
            }
      #We need to call super because Devise doesn't think we have sent any mail 
      super
  end
end

我在这里找到了对super 的调用:http://qnundrum.com/answer.php?q=254917

【问题讨论】:

  • 只是我想的,但是您是否尝试过覆盖 devise.rb 中的config.mailer 选项?
  • 我做到了,devise 仍在发送电子邮件,因为您必须在覆盖的底部调用 super
  • 如果你忽略了对 super 的调用会发生什么?
  • 我被这个问题困住了——你设法解决了吗?我正在考虑跳过super 并手动设置confirmation_sent_at,但我不确定它是否会起作用

标签: ruby-on-rails-3 devise actionmailer mailchimp


【解决方案1】:

我遇到了类似的问题。

您是否更新了设计初始化文件 (devise.rb) 以指定以下内容:

config.mailer = "MyDeviseMailer"  

您还需要将views/devise/mailer 中的所有文件移动到views/mydevisemailer。

我也会重新启动你的服务器。

【讨论】:

    猜你喜欢
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多