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?
The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.
By default, Rails uses CoffeeScript for JavaScript and SCSS for CSS. DHH has a great introduction during his keynote for RailsConf. The Rails asset pipeline provides an assets:precompile rake task to allow assets to be compiled and cached up front rather than compiled every time the app boots.
The asset pipeline is implemented by the sprockets-rails gem, and is enabled by default. You can disable it while creating a new application by passing the --skip-asset-pipeline option.
asset_path(source, options = {}) public. This is the entry point for all assets. When using the asset pipeline (i.e. sprockets and sprockets-rails), the behavior is “enhanced”. You can bypass the asset pipeline by passing in skip_pipeline: true to the options. All other asset *_path helpers delegate through this method ...
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With