如何使用选项“--bare"?在 Rails 3.1 中使用 CoffeeScript? [英] How can I use option "--bare" in Rails 3.1 for CoffeeScript?
问题描述
Someone know how can I use this option in Rails 3.1?
Now CoffeScript puts a function with .call(this)
on each file, but I want to remove this.
EDIT:
"Can't find variable" error with Rails 3.1 and Coffeescript" and "Pattern for CoffeeScript modules" have what I want. I'll change my global vars to use @global
scope.
I'd recommend against doing this. See my answer at Pattern for CoffeeScript modules for some of the reasons why. ("Making your CoffeeScript code incompatible with out-of-the-box Rails 3.1" is yet another reason.) Better to just use
window.a = b
or even
@a = b
instead of a = b
when you're trying to export something to global scope.
In previous versions of Rails 3.1, bare
compilation was enabled. This was classified as a bug, and fixed in RC1.
So while I strongly encourage you not to do this, here's how to turn bare compilation back on: Add
Tilt::CoffeeScriptTemplate.default_bare = true
to your environment.rb
.
这篇关于如何使用选项“--bare"?在 Rails 3.1 中使用 CoffeeScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!