Rails 3.1 RC 中的 File.read(Rails.root.join('public/images/email_banner.png')) 相当于什么?
在 Rails 3.0.X 中,此行曾经有效:
email_banner = File.read(Rails.root.join('public/images/email_banner.png'))
由于 Rails 3.1 RC 将图像目录移动到 app/assets/images 中,我收到错误:
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?
供您参考,我的 UserMailer 类的代码块:
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
....
是否有我可以使用的 asset_path?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经回答了自己的问题,只需更改您调用的路径即可。
You kind of answered your own question, you just need to change the path you call on.