简体   繁体   English

rails 3.1 coffeescript 文件扩展问题

[英]rails 3.1 coffeescript file extension problem

I have this stock rails 3.1 app, before even adding anything, I was testing to see if the assets are working as advertised我有这个 stock rails 3.1 应用程序,甚至在添加任何东西之前,我都在测试资产是否像宣传的那样工作

so i created this app/assets/javascripts/test.coffee所以我创建了这个 app/assets/javascripts/test.coffee

where test.coffee is just a其中 test.coffee 只是一个

alert "hi"提醒“嗨”

When I navigate to http://127.0.0.1:3000/assets/test.coffee , I do see当我导航到http://127.0.0.1:3000/assets/test.coffee时,我确实看到了

(function() {
  alert("hi");
}).call(this);

But if I do http://127.0.0.1:3000/assets/test.js , I get routing error;但是如果我这样做http://127.0.0.1:3000/assets/test.js ,我会收到路由错误; but I thought this is the correct behavior, not the above one.但我认为这是正确的行为,而不是上述行为。 What have I done wrong?我做错了什么?

Try renaming your your js file to test.js.coffee尝试将您的 js 文件重命名为test.js.coffee

Coffee extension indicates that this file should be preprocessed with coffee processor, same as: Coffee 扩展名表示该文件应使用咖啡处理器进行预处理,与:

  • index.html.haml is just index.html with haml processor or index.html.haml只是index.html与 haml 处理器或
  • style.css.sass is just style.css with sass processor style.css.sass只是style.css与 Z1F8DC276F8040001419C64E9D18 处理器

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

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