在Rails 3.0.X中,这条线用于工作:
email_banner = File.read(Rails.root.join('public/images/email_banner.png'))
由于Rails 3.1 RC将图像dir移动到app / assets / images,我得到错误:
Errno::ENOENT: No such file or directory - /Users/Foo/Sites/foobar/public/images/email_banner.png
我如何在Rails 3.1 RC中使用它?
供您参考,我的UserMailer类的代码块:
class UserMailer < ActionMailer::Base default :from => "from@example.com" def verification_email(user_id) @user = User.find(user_id) @verification_url = verification_url(:id => @user.verification_code) email_banner = File.read(Rails.root.join('public/images/email_banner.png')) attachments.inline['email_banner.png'] = email_banner mail(:from => "Foobar <support@foobar.com>",:to => "#{@user.full_name} <#{@user.email}>",:subject => 'Foobar Verification Email') end ....
我可以使用asset_path吗?
解决方法
您有点回答了自己的问题,只需要更改您调用的路径即可.
email_banner = File.read(Rails.root.join('app/assets/images/email_banner.png'))