How to include CoffeeScript in Rails

coffeescript, ruby-on-rails

Solution

If you have CoffeeScript enabled, Rails will generate a `.js.coffee` file for each of your controllers in `app/assets/javascripts`. That's where your CoffeeScript belongs, and you don't need to include `script` tags.

Read more in the guide: http://guides.rubyonrails.org/asset_pipeline.html

Problem

So CoffeeScript has shipped with Rails since 3.1? Fantastic! I'm getting into the syntax. I like simplicity. And yet, I can't seem to figure out how to include it on my site. I've tried including it between and that didn't work. I have one .erb file I want this to be in, new.html.erb (obviously, this is a Rails app): ``` <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>​ ``` And it doesn't show up at all. Ideas?

Original source