简体   繁体   English

如何在Rails中使用JavaScript

[英]How to use JavaScript in Rails

I'm reading Learning Rails 3. In the section on JavaScript it says to rename your file from *.js.coffee to just *.js if you want to use JavaScript instead of CoffeeScript. 我正在阅读Learning Rails3。在JavaScript一节中,如果您要使用JavaScript而不是CoffeeScript,则将文件从* .js.coffee重命名为* .js。 Well I did that and the JavaScript doesn't work. 好吧,我做到了,JavaScript无法正常工作。 When I converted the JavaScript to CoffeeScript (and renamed the source file back to *.js.coffee), everything works fine. 当我将JavaScript转换为CoffeeScript(并将源文件重命名为* .js.coffee)时,一切正常。

any ideas? 有任何想法吗? mike 麦克风

The first thing I'd do is check the server output of files, to ensure it's loading the javascript file. 我要做的第一件事是检查文件的服务器输出,以确保它正在加载javascript文件。

  1. Restart the development server 重新启动开发服务器
  2. Check the javascript include and the manifest file including it 检查javascript include和包含它的清单文件

The application.js file should consist of all the javascript files you want to include, however if it has '// require_tree .' application.js文件应包含要包含的所有javascript文件,但是如果文件具有'// require_tree'。 present then all the javascript present in the directory will be included. 当前,则目录中存在的所有javascript都将包括在内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM