问题
After a bundle install I am no longer able to add inline images to attachments. This is the error I get:
NoMethodError (undefined method `type_for' for MIME::Types:Class):
app/mailers/welcome_mailer.rb:14:in `add_inline_attachment!'
So clearly the type_for
method is being called on a class instead of an object.
Here is how I add the inline attachment, it follows the guidelines from ActionMailer:
attachments.inline['photo.png'] = File.read('path/to/photo.png')
I have tested that the file indeed exists and that it gets read. The issue appears to be gem-related.
回答1:
Upgrade to mime-types 3.1, released on 22 May 2016. mime-types 2.x only has six more planned updates and reaches end of life in November 2017, after which point no more support will be provided at all.
回答2:
It turns out that the update mime-types
gem, which is a dependency from ActionMailer
was updated from version 2.99.1
to version 3.0
, since this gem was not locked. It was pulled in as a dependency only.
From Gemfile.lock
:
mime-types (3.0)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0221)
Explicitly adding gem mime-types, (< 3)
to the Gemfile
fixed the issue for me.
来源:https://stackoverflow.com/questions/36709845/cannot-add-inline-attachment-with-actionmailer-in-rails-3