将application.js重命名为application.js.coffee?
启动一个新项目,我只是尝试将我的application.js重命名为application.js.coffee。
Rails引发错误:SyntaxError:意外的IDENTIFIER(在my_path / application.js.coffee中)
Application.js是空的,只是jquery包括:
//= require jquery //= require jquery_ujs
有任何想法吗? 谢谢
coffeescript中的注释用#
编写,因此替换为:
#= require jquery #= require jquery_ujs
你为什么想这么做?
建议不要在application.js中添加代码。
如果您需要运行咖啡脚本,只需在同一文件夹中创建一个咖啡文件,它将自动包含它。
从文件中的评论:
// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. // // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. //
这个文件不是你的常规.js文件,它的目的是为资源管道提供javascripts,这不是一个在这里添加代码的好习惯。
无论你需要做什么,都可以采取另一种方式……
- 使用CoffeeScript以编程方式检查复选框
- Rails 3.1。 如何防止Rails使用CoffeScript?
- Rails / Javascript:如何将rails变量注入(非常)简单的javascript中
- 在rails资产管道中的js.coffee文件中使用erb时出错
- 如何将CoffeeScript(或JavaScript)执行限制在Rails 3.1中的特定控制器和操作?
- 通过Rails中的视图加载.coffee文件
- 与客户端haml的angularjs
- Backbone和Rails关联:避免JSON HashWithIndifferentAccess错误
- 使用coffeescript延迟(去抖)ajax请求