Rails (Action Mailer) で複数のファイルを添付する方法

結論

attachments*1 のキーと値を複数定義すればよいです。

実例

attachments['foo.txt'] = File.read('tmp/hello_world.txt')
attachments['bar.txt'] = File.read('tmp/hello_ruby.txt')
attachments['foobar.txt'] = File.read('tmp/hello_rails.txt')

これで foo.txtbar.txtfoobar.txt という 3つ のファイルが添付されます。

*1:ハッシュ

Powered by はてなブログ