Rails 3.1中的mailer中的asset_url [英] asset_url in mailer on rails 3.1

查看:92
本文介绍了Rails 3.1中的mailer中的asset_url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的邮件收发器位于带有内置附件的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")

是否可以用 assets_url 之类的方式来改变它?

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

推荐答案

如果我理解正确,则希望使用资产管道的搜索功能来查找给定资产的本地路径,以便您不必硬编码它所在的目录。如果是这种情况,您可以执行以下操作:

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.

这篇关于Rails 3.1中的mailer中的asset_url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆