Get digested asset_path in model or controller

烂漫一生 提交于 2019-12-10 18:26:56

问题


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

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

What I do currently is generating a json that contains all needed fields of the articles, including the svg_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.

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


回答1:


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.



来源:https://stackoverflow.com/questions/33474285/get-digested-asset-path-in-model-or-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!