asset_url in mailer on rails 3.1
-
10-02-2021 - |
Question
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
?
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow