Rails 3.1rc4 asset pipeline broke after Ruby updat

2020-03-28 06:02发布

问题:

Somehow this is related but I'm not sure how/why?

Just upgraded from Ruby 1.9.2-p180 to 1.9.2-p290 via RVM's rvm upgrade command...and now my asset pipeline is 'broken'.

During rvm upgrade ... I noticed a bunch of errors for each gemset along lines of:

ERROR: Error running 'rvm gemset pristine' under ,
please read /Users/meltemi/.rvm/log//gemset.pristine.log

I let upgrade continue as there was not much interesting in the gemset.pristine.log... besides, /Users/meltemi/.rvm/log//gemset.pristine.log doesn't (can't?) exist in that exact path? two consecutive '//' in a pathname? Anyway...

Testing a small app and though it launches and appears to run it is not loading any assets (images, css, etc.). Development log has many Not Found errors (see below) about these missing assets even though they exist within app/assets/images and app/assets/stylesheets, etc... ?

Anyone know what's happening here? Seems like pipeline has broken down somehow... As if Rails no longer knows to look for assets in app/assets, perhaps? How can I test/verify/fix/re-activate this 'pipeline'?

$ rails s
=> Booting WEBrick
=> Rails 3.1.0.rc4 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-07-25 23:11:38] INFO  WEBrick 1.3.1
[2011-07-25 23:11:38] INFO  ruby 1.9.2 (2011-07-09) [x86_64-darwin10.8.0]
[2011-07-25 23:11:38] INFO  WEBrick::HTTPServer#start: pid=74881 port=3000


Started GET "/" for 127.0.0.1 at 2011-07-25 23:11:43 -0700
  Processing by PostsController#index as HTML
  Post Load (0.2ms)  SELECT "posts".* FROM "posts" ORDER BY posts.created_at DESC
  User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
  Photo Load (0.3ms)  SELECT "photos".* FROM "photos" WHERE "photos"."post_id" = 6
  CACHE (0.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
  Photo Load (0.2ms)  SELECT "photos".* FROM "photos" WHERE "photos"."post_id" = 5
  CACHE (0.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
  Photo Load (0.2ms)  SELECT "photos".* FROM "photos" WHERE "photos"."post_id" = 4
  CACHE (0.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
  Photo Load (0.2ms)  SELECT "photos".* FROM "photos" WHERE "photos"."post_id" = 2
  CACHE (0.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
  Photo Load (0.2ms)  SELECT "photos".* FROM "photos" WHERE "photos"."post_id" = 1
Rendered posts/index.html.haml within layouts/application (3016.4ms)
Rendered layouts/_header.html.haml (9.7ms)
Completed 200 OK in 3143ms (Views: 3138.2ms | ActiveRecord: 2.9ms)


Started GET "/assets/application.css" for 127.0.0.1 at 2011-07-25 23:11:47 -0700
Served asset /application.css - 404 Not Found (1ms)

ActionController::RoutingError (No route matches [GET] "/assets/application.css"):


Rendered /Users/meltemi/.rvm/gems/ruby-1.9.2-p290@rails3/gems/actionpack-3.1.0.rc4/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.2ms)


Started GET "/assets/application.js" for 127.0.0.1 at 2011-07-25 23:11:47 -0700
Served asset /application.js - 404 Not Found (0ms)

ActionController::RoutingError (No route matches [GET] "/assets/application.js"):


Rendered /Users/meltemi/.rvm/gems/ruby-1.9.2-p290@rails3/gems/actionpack-3.1.0.rc4/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.8ms)


Started GET "/assets/racer-outline.png" for 127.0.0.1 at 2011-07-25 23:11:48 -0700
Served asset /racer-outline.png - 404 Not Found (0ms)

ActionController::RoutingError (No route matches [GET] "/assets/racer-outline.png"):


Rendered /Users/meltemi/.rvm/gems/ruby-1.9.2-p290@rails3/gems/actionpack-3.1.0.rc4/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (3.2ms)


Started GET "/assets/ray.png" for 127.0.0.1 at 2011-07-25 23:11:48 -0700
Served asset /pogo.png - 404 Not Found (0ms)

ActionController::RoutingError (No route matches [GET] "/assets/ray.png"):


Rendered /Users/meltemi/.rvm/gems/ruby-1.9.2-p290@rails3/gems/actionpack-3.1.0.rc4/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.2ms)

回答1:

It seems that version 2.0.0.beta.11 of sprockets broke the assets pipeline. Putting

gem 'sprockets', '= 2.0.0.beta.10'

into your Gemfile seems to fix the problem (it worked for me). Rails seems to automatically use the most recent version of the beta for whatever reason so if you just started your project recently or updated all your gems it probably broke it.

Note that this info isn't mine originally, I got the fix from http://groups.google.com/group/rubyonrails-core/browse_thread/thread/59d8c7813b4d1bbe?pli=1

He explains the problem for ver. 2.0.0.beta.11 but I was using ver. 2.0.0.beta.12 with the same results so it seems that they haven't fixed it yet.

EDIT: It seems that upgrading your rails to 3.1.rc5 also fixes the problem



回答2:

I ended up just blowing out the whole problematic gemset and starting anew. Lesson learned:

Don't trust rvm upgrade. Install the new Ruby w/in RVM. Then manually rebuild (or bundle install) your gemsets.