因此CoffeeScript自3.1以來隨Rails一起發佈了嗎?太棒了!我正在進入語法。我喜歡簡單。如何在Rails中包含CoffeeScript
然而,我似乎無法弄清楚如何將它包含在我的網站上。我試過在它之間包括它,但沒有奏效。
我有一個.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>
而且它不會顯示在所有。想法?
Alrighty,但我怎麼會在我的new.html.erb文件中調用這個?這是一個倒計時腳本。 – rumblestrut 2012-04-24 20:43:44
你可以調用coffescript倒計時函數,就像調用任何javascript倒計數函數一樣。編譯期間,Coffescript被轉換爲javascript。如果您還沒有閱讀並理解資產管道指南,您將不會走得太遠。 – richardsun 2012-04-25 17:42:47