为什么= javascript_include_tag:默认值不能在Rails 3.1中的haml布局中工作

AKW*_*KWF 9 ruby-on-rails ruby-on-rails-3.1

男人,WTH正在继续这个东西.你知道Rails 3.1中该行实际上做了什么吗?

<script src="/assets/defaults.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

正如他们在ESPN上所说,"来吧,伙计."

我知道资产不再被视为二等公民.但似乎他们甚至无法在此候选版本中获得绿卡.在新的app/assets/javascripts/application.js中:

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
Run Code Online (Sandbox Code Playgroud)

SOOOOO.我应该下载jquery吗?我该怎么办?因为除了application.js之外,javascripts目录中没有任何内容.

加重.然而它是免费的,所以我如何抱怨?无论如何,这些问题看起来很基本,但我很感激您提供的任何帮助.

Rya*_*igg 17

在Rails 3.1中,不再存在"默认值",而是在application.js文件中指定的是"默认值".您将使用以下行包含此文件:

 javascript_include_tag "application"
Run Code Online (Sandbox Code Playgroud)

jqueryjquery_ujs文件来与jquery-rails它在默认的Rails 3.1的宝石Gemfile.

//= require文件中的行告诉Sprockets您需要一个文件,在这种情况下,该文件将jquery.js来自内部jquery-rails,其中//= require_tree .将要求所有其他JavaScript文件位于同一目录中,application.js并将它们全部连接到一个文件中.

您可以在此处阅读有关资产管道的更多信息.

  • 谢谢RB.这让我发疯了.我觉得漂亮的脚手架还没赶上.我无法相信JS文件嵌入在gem中.这对我来说似乎有点过于"神奇".我无法弄清楚Sprockets如何看待那颗宝石,我不喜欢它. (2认同)