获取模型或控制器中的摘要资产路径 [英] Get digested asset_path in model or controller

查看:89
本文介绍了获取模型或控制器中的摘要资产路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Article模型,其中有一个字段svg_path.

I have an Article model, which has a field svg_path.

我用fabricjs画一个可以包含多篇文章并且可以修改的画布.

I use fabricjs to draw a canvas that can contain multiple articles and is modifiable.

我目前正在生成一个json,其中包含文章的所有必填字段,包括svg_path.

What I do currently is generating a json that contains all needed fields of the articles, including the svg_path.

当我尝试使用asset_path帮助器时(Article模型或控制器中> http://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html#method-i-asset_path ),它将始终只返回没有摘要的路径,它在开发环境中有效,但在生产环境中无效.在那里,我包括了这样的助手:

When I try to use the asset_path helper (http://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html#method-i-asset_path) in either my Article model or controller it will always just return the path without the digest, which works in development environment but not in production. There I include the helper like this:

include ActionView::Helpers::AssetUrlHelper

asset_path(svg_path)

如果我在视图中调用此帮助器,它将生成包括摘要哈希的正确路径.

If I call this helper in the view it will generate the correct path including the digest hash.

如何在我的json对象中获得正确的路径?

How can I get the correct path in my json objects?

推荐答案

解决方案是这样调用助手:

The solution was to call the helper like this:

ActionController::Base.helpers.asset_path(svg_path)

在此之前,我已经在问题中加入了帮助者,但这并没有达到预期的结果.

Before that I had included the helper as in my question, which didn't result in the expected result.

这篇关于获取模型或控制器中的摘要资产路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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