9

I am on a Macbook Pro and I created a new Rails 3.2 app, but the assets pipeline does not work. Here is what I did:

$ rails version
  Rails 3.2.5
$ rails new test_assets
$ cd test_assets
$ rails server

The server is started OK, but if I visit http://0.0.0.0:3000/assets/application.js, it turns out the manifest file is not processed at all, it shows:

//... some comments ...
//= require jquery
//= require jquery_ujs
//= require_tree .
;

I tried to do the exactly the same steps on my other Macbook Pro. It works well. Visiting http://0.0.0.0:3000/assets/application.js on that machine shows a compiled javascript file with all the contents.

I have read http://railscasts.com/episodes/279-understanding-the-asset-pipeline and http://guides.rubyonrails.org/asset_pipeline.html, and I searched for hours on the web but with no clue.

Your help is really appreciated!

4

7 回答 7

3

建议:安装 node.js 或gem 'therubyracer', :platforms => :ruby在 Gemfile 中取消注释

我遵循相同的步骤,我的日志文件看起来像这样......如果你启动服务器并请求 /assets/application.js,你的会是什么样子?如您所见,我使用的是 3.2.6,它编译了我的 application.js

=> Booting WEBrick
=> Rails 3.2.6 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-07-19 22:50:02] INFO  WEBrick 1.3.1
[2012-07-19 22:50:02] INFO  ruby 1.9.3 (2012-02-16) [x86_64-darwin11.3.0]
[2012-07-19 22:50:02] INFO  WEBrick::HTTPServer#start: pid=21393 port=3000


Started GET "/assets/rails.png" for 127.0.0.1 at 2012-07-19 22:50:13 -0500
Connecting to database specified by database.yml
Served asset /rails.png - 200 OK (9ms)


Started GET "/assets/application.js" for 127.0.0.1 at 2012-07-19 22:50:23 -0500
Compiled jquery.js  (2ms)  (pid 21393)
Compiled jquery_ujs.js  (0ms)  (pid 21393)
Compiled application.js  (26ms)  (pid 21393)
Served asset /application.js - 200 OK (74ms)
[2012-07-19 22:50:24] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
于 2012-07-20T03:54:43.310 回答
3

我遇到过同样的问题!

将 Ruby 从 2.0.0 降级到 1.9.3 解决了这个问题

于 2013-06-28T22:32:24.677 回答
0

面临完全相同的情况。

我发现我使用像 v2.0.0rc 之类的 ruby​​ 或类似的东西,如果我将它降级到 1.9.3p194(两者都在 Rbenv 下),一切都会完美。

尽管您可以在视图中使用 helper,例如<%= javascript_include_tag "jquery", "jquery_ujs" %>,但即使使用 ruby​​2.0.0,它也对我有所帮助。

于 2013-04-18T08:36:09.553 回答
0

我今天遇到了同样的问题,我准备将 Ruby 从 2.0 降级到 1.9.3 以解决 application.js 无法编译的问题。该问题发生在安装了 Ruby 2.0(和 Rails 3.2.8)的生产服务器上。在开发机器上(Ruby 1.9.3 和 Rails 3.2.8)application.js 编译得很好。

最后,我将生产服务器从 Rails 3.2.8 升级到 3.2.14;删除 Gemfile.lock,然后运行 ​​bundle install。然后我重新编译了资产,瞧,application.js 编译了资产。

我想与 Stackoverflow 的观众分享这个,也许这会解决别人的问题。

于 2013-11-14T06:38:14.573 回答
0

使用 ruby​​ 2.0 的第一个官方支持的 rails 3.2 版本是 3.2.13。因此将您的 rails 版本升级到 rails 3.2.13 将解决问题。

升级步骤:

1) 将 Gemfile 中的 rails 版本更改为 gem 'rails', '3.2.22'。

2)捆绑更新轨道

于 2017-03-08T12:22:48.233 回答
-1

在开发时,资产没有预编译。如果你想看到它们,你应该运行bundle exec rake assets:precompile.

于 2012-07-20T01:41:16.967 回答
-3

打开 enviornment/development.rb 并设置 config.assets.debug = false 。而已

于 2013-01-28T14:25:58.567 回答