【发布时间】:2013-03-30 09:42:49
【问题描述】:
我正在尝试让咖啡脚本与 Sinatra 一起使用。我对这两种技术都是新手,所以这可能很愚蠢。我的问题似乎是咖啡脚本编译为 javascript 但不在页面上执行,而是显示为 html。
#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 是如何嵌入其中的?此外,上面还有一个不一致之处——
"hello world"与"hello kids"。 -
当我说“在 HTML 中”时,我的意思是当我查看页面的源代码时。不一致的问题已修复 - 如有任何混淆,我们深表歉意。
-
好吧,我明白,但我想问:你是如何在 Sinatra 端创建该页面的?
标签: sinatra coffeescript