3

I am trying to use this bundle with the coffee files generated for each controller. I'm just delving into this for the first time by just doing the traditional

$ ->
    alert('Hello World!')

It works fine when I view the page, and doing Command+B also displays the desired JS code. However, I can't do Command+R. I just get ReferenceError: $ is not defined. I understand that it probably can't reference the jQuery file that defines $, but can't for the life of me figure out how to do that. Come to think of it, I'm wondering if it's a sensible thing to want to do this...

What's the best practice when using CoffeeScript and TextMate in Rails 3.1 development?

Thanks, Dany.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
codedog
  • 2,488
  • 9
  • 38
  • 67

1 Answers1

3

It works fine when I view the page, and doing Command+B also displays the desired JS code. However, I can't do Command+R.

Right, because Command+R means "run this .coffee file under NodeJS" (basically equivalent to coffee myfile.coffee). Even if $ weren't an issue ($ = require 'jquery' will fix this, after you npm install jquery), alert certainly would be.

Now, you might be thinking: "OK, crazy idea: What if I split my front-end into Node modules, which are easy to test, and then convert them to browser-friendly code for deployment?" In that case, I have good news for you: sstephenson stole your crazy idea months ago, and it's called Stitch. Give it a try!

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
Trevor Burnham
  • 76,828
  • 33
  • 160
  • 196