Rails 3.1 RC 中的 File.read(Rails.root.join('public/images/email_banner.png')) 相当于什么?

发布于 2024-11-14 07:29:50 字数 1251 浏览 3 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尘世孤行 2024-11-21 07:29:50

您已经回答了自己的问题,只需更改您调用的路径即可。

email_banner = File.read(Rails.root.join('app/assets/images/email_banner.png'))

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'))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文