【问题标题】:Generating Mustache Template With Asset Images in Rails在 Rails 中使用资产图像生成 Mustache 模板
【发布时间】:2020-04-07 16:55:35
【问题描述】:

我正在我的 rails 应用程序的控制器中生成一个 Mustache 模板。我能够很好地生成html。我的问题是我无法从 assets 文件夹中加载图像。

我尝试使用 ActionController::Base.helpers.image_tagActionController::Base.helpers.asset_path,然后将其作为变量传递到 Mustache 模板中的图像标记中,作为资产路径的 <img src="{{ asset_path }}" />image_tag 的输出原样<div> {{ image_tag }} </div>

我知道 image_tag 和 assets_path 正在拾取图像,因为当我输入不正确的路径时,它会输出错误。

有人对如何将此图像链接到 Mustache 模板有任何想法吗?

【问题讨论】:

  • 您能分享一下您是如何在控制器中创建模板的吗?

标签: ruby-on-rails mustache


【解决方案1】:

此问题已解决。该错误与 Mustache 无关,而是与应用程序的下一阶段有关,即从生成的 HTML 生成 PDF。

作为参考,我使用Rails.root.join('app','assets','..path to image')作为图片路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    相关资源
    最近更新 更多