ruby-on-railsruby-on-rails-4asset-pipelinefabricjs

Get digested asset_path in model or controller


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?


Solution

  • 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.