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

查看:29
本文介绍了如何使用选项“--bare"?在 Rails 3.1 中用于 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.

无法找到变量"错误与 Rails 3.1 和Coffeescript" 和 "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

当您尝试将某些内容导出到全局范围时,而不是 a = b.

instead of a = b when you're trying to export something to global scope.

在以前的 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.

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

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