简体   繁体   English

Rails 3.1资产管道看不到文件

[英]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. 我们正在将我们的应用程序从Rails 2升级到Rails 3.1,并且在资产管道方面遇到了麻烦。

I've got the following in my config/application.rb: 我的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 然后在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. 我知道这不是管道所需的行为,但是我们这样做是为了确保当我们将升级合并回我们的master分支时,所有旧文件都得到正确处理。

I then have the following file, "all.css," in my public/stylesheets directory: 然后,在我的public / stylesheets目录中有以下文件“ all.css”:

/*
*= 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: 我从我的layouts / application.html.erb文件中调用它,如下所示:

<%= stylesheet_link_tag "all" %>

Loading things up in a browser, however, I get no styles (or javascript, for that matter). 但是,将内容加载到浏览器中时,我没有样式(或javascript)。 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. Firebug和Chrome告诉我,正在/ assets中查找.css和.js文件-好像管道没有在搜索所有内容并将其捆绑在一起。

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. 如果我将“ all.css”移动到/ app / assets中,它仍然找不到。 Moving it into /assets stops the error, but the stylesheet doesn't compile and I still don't get any styles in my browser. 将其移至/ assets可以停止该错误,但是样式表无法编译,并且我的浏览器中仍然没有任何样式。

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. 我在(memcached -d)上执行了它,现在我的所有资产都出现了。 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. 完成这些操作后,我建议您将清单名称更改为application.css和application.js,因为它们是默认名称,从这些名称开始您会遇到较少的问题。 Edit your question if it still does not work and I'll see if I can help after that. 如果您的问题仍然无法解决,请编辑您的问题,之后我会为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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