简体   繁体   中英

Rails 3.1 asset pipeline not seeing files

We're upgrading our app from Rails 2 to Rails 3.1, and I'm having trouble with the asset pipeline.

I've got the following in my config/application.rb:

if defined?(Bundler)
  Bundler.require *Rails.groups(:assets => %w(development test))
  # Bundler.require(:default, :assets, Rails.env)
end

# Enable the asset pipeline
config.assets.enabled = true
# config.assets.prefix = "/assets"
config.assets.paths << "#{Rails.root}/public/images"
config.assets.paths << "#{Rails.root}/public/stylesheets"
config.assets.paths << "#{Rails.root}/public/javascripts"

config.assets.version = '1.0'

And then this in development.rb

# Do not compress assets
config.assets.compress = false
config.assets.debug = true

I know this isn't the desired behavior for the pipeline, but we are doing it this way to make sure that when we merge the upgrade back into our master branch, all the old files are accounted for properly.

I then have the following file, "all.css," in my public/stylesheets directory:

/*
*= require ezform
*= require jquery-ui-1.8.9.custom
*= require thickbox
*= require yui-upload
*= require styles
*/

I am calling it from within my layouts/application.html.erb file like so:

<%= stylesheet_link_tag "all" %>

Loading things up in a browser, however, I get no styles (or javascript, for that matter). Firebug and Chrome tell me that the .css and .js files are being looked for in "/assets" - it's like the pipeline isn't searching through everything and bundling it like it should.

The error looks like this:

GET http://localhost:3000/assets/jquery-dependent.js 500 (Internal Server Error)

If I move "all.css" into /app/assets, it still won't find it. Moving it into /assets stops the error, but the stylesheet doesn't compile and I still don't get any styles in my browser.

There's also a slew of errors that look like this in my log:

Started GET "/assets/defaults.js?body=1" for 127.0.0.1 at 2011-12-22 14:35:36 -0600
[2011-12-22 14:35:36] ERROR NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
    /Users/kevin/.rvm/gems/ruby-1.9.2-p0@media3/gems/rack-1.3.5/lib/rack/handler/webrick.rb:71:in `service'
    /Users/kevin/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
    /Users/kevin/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
    /Users/kevin/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
cache: [GET /assets/defaults.js?body=1] miss, store
Served asset /defaults.js - 200 OK (1ms)

What am I missing?

sigh It was memcached. I tured it on (memcached -d) and now all my assets are appearing. I'm not sure why, so I'd love some explanation. Otherwise, it's working.

There are a while bunch of settings that need to be added into the development and application config files for the pipeline to work correctly.

Check out the last section of the pipeline guide for details of these.

Once you've done that I suggest that you change the manifest names to application.css and application.js as these are the default names and you'll run into fewer problems starting with those. Edit your question if it still does not work and I'll see if I can help after that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM