我正在尝试让coffeescript与Sinatra一起工作。我对这两种技术都很陌生,所以这可能是愚蠢的。我的问题似乎是咖啡脚本编译为JavaScript,但不在页面上执行,而是出现为HTML。如何与Sinatra一起使用coffeescript
#sinatra app
require 'coffee-script'
get "/test.js" do
coffee :hello
end
#hello.coffee
alert "hello world"
#My page (/test.js) doesn't execute the js - just displays the code
#On screen in the browser I get this:
(function() {
alert("hello world");
}).call(this);
#In the HTML I get this within the body tags
<pre style="word-wrap: break-word; white-space: pre-wrap;">(function() {
alert('hello world!');
}).call(this);
</pre>
当你说“在HTML中”,你指的是什么HTML?你的JavaScript是如何嵌入其中的?另外,上面有一个不一致的地方 - “你好的世界”与“你好的孩子”。 – 2011-04-15 14:56:38
当我说“在HTML中”时,我的意思是当我查看页面的源代码时。不一致 - 对于任何混淆抱歉。 – 2011-04-16 20:09:03
对,我明白,但我问:你是如何在Sinatra的结尾创建这个页面的? – 2011-04-17 00:05:59