从静态索引页面调用Javascript

时间:2022-09-13 13:20:30

All I have in the public folder, index.html file of my rails is this:

我在公共文件夹中的所有内容,我的rails的index.html文件是这样的:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <script src="jstester.js">
    </script>
</body>
</html>

and all I have in the assets->javascripts folder is that I added a jstester.js file in it and all it has for now is just one line of code:

我在assets-> javascripts文件夹中的所有内容是我在其中添加了一个jstester.js文件,它现在只有一行代码:

alert("fffsdfasdsad");

Everything else is just coming from the Rails defaults. Now when I run the rails server, should I see a message box? Because I don't see anything. What is missing?

其他所有东西都来自Rails默认值。现在当我运行rails服务器时,我应该看到一个消息框吗?因为我没有看到任何东西。缺什么?

1 个解决方案

#1


3  

Assets served via the asset pipeline always come from /assets. The path to a JavaScript file served from the asset pipeline is /assets/<file>.js, not just <file>.js. Fix your src attribute:

通过资产管道提供的资产总是来自/资产。从资产管道提供的JavaScript文件的路径是/assets/ .js,而不仅仅是 .js。修复你的src属性:

<script src="/assets/jstester.js"></script>

#1


3  

Assets served via the asset pipeline always come from /assets. The path to a JavaScript file served from the asset pipeline is /assets/<file>.js, not just <file>.js. Fix your src attribute:

通过资产管道提供的资产总是来自/资产。从资产管道提供的JavaScript文件的路径是/assets/ .js,而不仅仅是 .js。修复你的src属性:

<script src="/assets/jstester.js"></script>