在Rails中使用Asset图片生成胡子模板。

问题描述 投票:0回答:1

我在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和asset_path正在接收图片,因为当我输入错误的路径时,它就会输出一个错误。

有谁知道如何将这个图片链接到Mustache模板上?

ruby-on-rails mustache
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.