Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 操作邮件程序附件的未定义方法URL_Ruby On Rails_Ruby On Rails 4_Actionmailer - Fatal编程技术网

Ruby on rails 操作邮件程序附件的未定义方法URL

Ruby on rails 操作邮件程序附件的未定义方法URL,ruby-on-rails,ruby-on-rails-4,actionmailer,Ruby On Rails,Ruby On Rails 4,Actionmailer,我得到的错误是: ActionView::Template::Error (undefined method `url' for nil:NilClass) 我的附件是零 <%= image_tag attachments['tippedlogods.png'].url %> 在my production.rb中: config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery

我得到的错误是:

ActionView::Template::Error (undefined method `url' for nil:NilClass)
我的附件是零

<%= image_tag attachments['tippedlogods.png'].url %>
在my 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指南


注意Rails 4~

在添加附件之前,您首先要呼叫
邮件。因此,在呈现模板时没有附件

更改语句的顺序

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

链接到Rails 3。也许有什么改变了?以下是相关章节:
attachments.inline['tippedlogods.png'] = File.read("app/assets/images/tippedlogods.png")
mail(to: @order.email, subject: "Order Confirmation", content_type: "text/html")