那么 CoffeeScript 从 3.1 开始就与 Rails 一起发布了?极好的!我正在进入语法。我喜欢简单。
然而,我似乎无法弄清楚如何将它包含在我的网站上。我试过在两者之间包含它,但没有奏效。
我有一个我想要的 .erb 文件,new.html.erb(显然,这是一个 Rails 应用程序):
<script type="text/coffeescript">
# Countdown to date script provided by JavaScriptKit.com
# http://www.javascriptkit.com/script/script2/count.shtml
montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
countdown(yr,m,d) ->
today=new Date()
todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
todaym=today.getMonth()
todayd=today.getDate()
todaystring=montharray[todaym]+" "+todayd+", "+todayy
futurestring=montharray[m-1]+" "+d+", "+yr
difference=(Math.round((Date.parse(futurestring)-Date.parse(todaystring))/(24*60*60*1000))*1)
if (difference==0) and document.write(current)
elseif (difference>0) document.write("ONLY "+difference+" DAYS LEFT!")
countdown(2012,4,30)
</script>
而且它根本没有出现。想法?