Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 => "[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?

like image 738
Christian Fazzini Avatar asked Jun 06 '11 21:06

Christian Fazzini


1 Answers

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'))
like image 163
Douglas F Shearer Avatar answered Nov 19 '22 16:11

Douglas F Shearer