Rails 3.1 上邮件程序中的 asset_url

发布于 2024-12-11 12:44:05 字数 219 浏览 0 评论 0原文

我的邮件程序位于 Rails 3.1 上,它有一个内联附件。

要打开该附件,我使用以下代码:

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

有没有办法用 assets_url 之类的东西来更改它?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当爱已成负担 2024-12-18 12:44:05

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

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

:将使用标准管道/链轮搜索来定位资产,并为您提供文件的完全限定本地路径。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文