Acquire Asset Path from JavaScript

前端 未结 6 1003
梦如初夏
梦如初夏 2021-02-18 16:17

I need to display images on an HTML5 canvas that are in the Rails asset pipeline, but I need to know the path for the asset from JavaScript. I\'m using js-routes for other parts

6条回答
  •  星月不相逢
    2021-02-18 16:35

    In the Rails Asset Pipeline guide, they give an example of coding assets in your stylesheets by preprocessing the stylesheets with ERB. You can use the same technique with JavaScript, assuming you tack an .erb to the end of the filename:

    var someAssetPath = "<%= asset_path('some_image.png') %>";
    

提交回复
热议问题