rails将devise与sendgrid模板集成在一起

时间:2016-08-24 09:54:56

标签: ruby-on-rails devise sendgrid

我想使用sendgrid模板发送设计确认邮件,所以我在sendgrid上有一个模板,我将使用这个代码在rails

class CustomMailer < Devise::Mailer
  helper :application # gives access to all helpers defined within `application_helper`.
  include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
  default template_path: 'devise/mailer' # to make sure that your mailer uses the devise views

  def confirmation_instructions(record, token, opts={})

    headers["X-SMTPAPI"] => {
                "sub": {
                    "%record%" => [record],
                    "%token%" => [token],
                },
                "filters": {
                    "templates": {
                        "settings": {
                            "enable": 1,
                            "template_id": 'id here'
                        }
                    }
                }
            }.to_json

    mail(
        subject: "subject"

    )
end

问题是我在尝试发送邮件时遇到此错误:

An ActionView::Template::Error occurred in registrations#create:

  undefined method `url' for nil:NilClass
  app/views/devise/mailer/confirmation_instructions.html.erb:5:in `_app_views_devise_mailer_confirmation_instructions_html_erb___3785479096466683301_70149801011060'

因此看起来rails试图以默认方式发送电子邮件并且没有触发任何流程

0 个答案:

没有答案