加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Action Mailer附件的未定义方法URL

发布时间:2020-12-17 02:40:54 所属栏目:百科 来源:网络整理
导读:我得到的错误: ActionView::Template::Error (undefined method `url' for nil:NilClass) 我有这个附件正在增加零 %= image_tag attachments['tippedlogods.png'].url % 话虽这么说,我已经在方法中声明了发送电子邮件的附件,这里: def confirmation(order)
我得到的错误:

ActionView::Template::Error (undefined method `url' for nil:NilClass)

我有这个附件正在增加零

<%= image_tag attachments['tippedlogods.png'].url %>

话虽这么说,我已经在方法中声明了发送电子邮件的附件,这里:

def confirmation(order)
    @order = order
    mail(to: @order.email,subject: "Order Confirmation",content_type: "text/html")
    attachments.inline['tippedlogods.png'] = File.read("app/assets/images/tippedlogods.png")
  end

在我的production.rb中:

config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = { :host => 'hidden-peak-xxxx.heroku.com',:only_path => false}
  config.action_mailer.asset_host = 'hidden-peak-xxxx.heroku.com'
  ActionMailer::Base.smtp_settings = {
  :address    => "smtp.sendgrid.net",:port       => 587,:user_name  => ENV['SENDGRID_USERNAME'],:password   => ENV['SENDGRID_PASSWORD'],:domain     => ENV['SENDGRID_DOMAIN'],:authentication  => :plain
  }

这不是在确认电子邮件中发送图像的方法吗?

我正在关注RoR Guides here ……

注意Rails 4~

解决方法

在添加附件之前,您首先要调用邮件.所以渲染模板时没有附件!

http://apidock.com/rails/ActionMailer/Base/mail

更改语句的顺序.

attachments.inline['tippedlogods.png'] = File.read("app/assets/images/tippedlogods.png")
mail(to: @order.email,content_type: "text/html")

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读