asset_url in mailer on rails 3.1

别等时光非礼了梦想. 提交于 2019-11-30 13:27:06

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/7854243/asset-url-in-mailer-on-rails-3-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!