Acquire Asset Path from JavaScript

前端 未结 6 986
梦如初夏
梦如初夏 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-18 16:38

    Checkout the js_assets(Javascript helper in rails projects) gem. I think it is precisely what you need.

    From the documentation:

    Get the path to the template app/assets/javascripts/rubrics/views/index.html in javascript: var path = asset_path('rubrics/views/index.html')

提交回复
热议问题