In Rails 3.0.X, this line used to work:
email_banner = File.read(Rails.root.join('public/images/email_banner.png'))
Since Rails 3.1 RC moved the images dir into app/assets/images, I get the error:
Errno::ENOENT: No such file or directory - /Users/Foo/Sites/foobar/public/images/email_banner.png
How would I get this to work in Rails 3.1 RC?
For your reference, the code block for my UserMailer class:
class UserMailer < ActionMailer::Base
default :from => "[email protected]"
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 <[email protected]>",
:to => "#{@user.full_name} <#{@user.email}>",
:subject => 'Foobar Verification Email')
end
....
Is there an asset_path I can use?
You kind of answered your own question, you just need to change the path you call on.
email_banner = File.read(Rails.root.join('app/assets/images/email_banner.png'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With