Whats the equivalent of File.read(Rails.root.join('public/images/email_banner.png')) in Rails 3.1 RC?
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 => "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
....
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'))
精彩评论