如何使用选项“ - 裸”在Rails 3.1 for CoffeeScript? [英] How can I use option "--bare" in Rails 3.1 for CoffeeScript?

查看:120
本文介绍了如何使用选项“ - 裸”在Rails 3.1 for CoffeeScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何在Rails 3.1中使用此选项?
现在CoffeScript在每个文件中添加一个 .call(this)的函数,但是我想删除它。

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:
可以't find variable'error with Rails 3.1 and Coffeescript and Pattern for CoffeeScript模块有我想要的。我将更改全局变量以使用 @global 范围。

"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.

推荐答案

我建议不要这样做。有关某些原因,请参见 CoffeeScript模块模式的答案。 (使您的CoffeeScript代码与开箱即用的Rails 3.1不兼容是另一个原因。)更好地使用

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

或甚至

@a = b

在以前的Rails 3.1版本中, bare 编译已启用。这是分类为错误,并在RC1中修复。

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

environment.rb 。

to your environment.rb.

这篇关于如何使用选项“ - 裸”在Rails 3.1 for CoffeeScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆