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'))

由于Rails3.1RC将images目录移到了app/assets/images中,我得到了错误:

Errno::ENOENT: No such file or directory - /Users/Foo/Sites/foobar/public/images/email_banner.png

我该如何在Rails3.1RC中实现这一点?

供您参考,我的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
....

有我可以使用的资产路径吗?

你有点回答了自己的问题,你只需要改变你调用的路径。

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

相关内容

  • 没有找到相关文章

最新更新