Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asset_url in mailer on rails 3.1

I have my mailer on rails 3.1 which has an inline attachment.

To open that attachment i use this code:

attachments["rails.png"] = File.read("#{Rails.root}/app/assets/images/Rails.png")

is there a way to change that with something like assets_url ?

like image 477
Nicos Karalis Avatar asked Oct 21 '11 19:10

Nicos Karalis


1 Answers

If I understand correctly, you want to use the asset pipeline's search functionality to locate the local path for a given asset so you don't have to hard-code which directory it's in. If that's the case, you want to do this:

<YourAppName>::Application.assets.find_asset('Rails.png').pathname

This will locate the asset using standard pipeline/sprockets searching, and give you the fully qualified local path to the file.

like image 145
Irongaze.com Avatar answered Nov 03 '22 13:11

Irongaze.com