2014-06-25 126 views
4

的錯誤,我得到:未定義的方法URL行動梅勒附件

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指南here ...

注意軌道4〜

+0

鏈接是Rails 3的。也許有什麼改變?這裏是相關的部分:http://guides.rubyonrails.org/action_mailer_basics.html#complete-list-of-action-mailer-methods – Chloe

回答

5

要調用mail首先你添加附件之前。所以在渲染模板時沒有附件!

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

更改語句的順序。

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

哈哈,這是有道理的... – Peege151