从JavaScript获取资产路径 [英] Acquire Asset Path from JavaScript

查看:76
本文介绍了从JavaScript获取资产路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Rails资产管道中的HTML5画布上显示图像,但是我需要从JavaScript知道资产的路径.我在应用程序的其他部分使用了 js-routes ,但它似乎没有提供了一种通往资产管道中某物的路径的方法.

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 of the application, but it doesn't appear to provide a way to get the path to something in the asset pipeline.

从JavaScript获取指向Rails资产(例如图像)的路径的正确方法是什么?

What's the correct way to obtain the path to a Rails asset (e.g., an image) from JavaScript?

推荐答案

在Rails中

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') %>";

这篇关于从JavaScript获取资产路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆