资产管道已损坏:未在css和js文件上进行编译

时间:2012-06-17 07:03:18

标签: ruby-on-rails ruby asset-pipeline ruby-on-rails-3.2

我启动了一个新的Rails 3.2.5项目,资产管道不再起作用了。 CSS和Javascript文件不再编译。

这是尝试生成资产时日志的输出:

    Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-06-16 23:59:11 -0700
Served asset /application.css - 200 OK (0ms)
[2012-06-16 23:59:11] ERROR NoMethodError: undefined method `each' for nil:NilClass
    /Users/greg/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rack-1.3.6/lib/rack/handler/webrick.rb:71:in `service'
    /Users/greg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
    /Users/greg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
    /Users/greg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:

Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-06-16 23:59:11 -0700
Served asset /application.js - 200 OK (0ms)
[2012-06-16 23:59:11] ERROR NoMethodError: undefined method `each' for nil:NilClass
    /Users/greg/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rack-1.3.6/lib/rack/handler/webrick.rb:71:in `service'
    /Users/greg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
    /Users/greg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
    /Users/greg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
183:in `block in start_thread'

更新

<!DOCTYPE html>
<html>
<head>
  <title>Shorai</title>
  <%= csrf_meta_tags %>
</head>
<body id=<%= params[:controller].sub('_controller', '') %>>

  <% if current_user %>
    <%= current_user.name %>
    <%= link_to "Log out", signout_path %>
  <% else %>
    <%= link_to "Sign in", "/auth/37signals" %>
  <% end %>

  <%= yield %>

  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= javascript_include_tag "application" %>
</body>
</html>

UPDATE2:

application.scss

 *
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the top of the
 * compiled file, but it's generally better to create a new file per style scope.
 *
 *= require_self
 *= require_tree .
 */

UPDATE3: http://f.imgtmp.com/Onpqv.png

我不知道造成这种情况的原因是什么,有人有想法吗? 格雷格

4 个答案:

答案 0 :(得分:7)

当我使用 memcached 存储启用缓存(在开发模式下)时出现此错误,但 memcached 进程未运行(Rails 3.2.8,Win7)

因此,解决方案是简单地启动 memcached 并重新启动Rails服务器。

答案 1 :(得分:3)

将memcache激活为缓存存储(config.cache_store = :dalli_store)后,我遇到了类似的问题。我可以通过显式停用Rack :: Cache中间件(config.action_dispatch.rack_cache = nil)或设置

来解决这个问题
config.action_dispatch.rack_cache = {
  :metastore    => Dalli::Client.new,
  :entitystore  => 'file:tmp/cache/rack/body',
  :allow_reload => false
}

请参阅https://github.com/rails/rails/issues/8366

答案 2 :(得分:2)

我有类似的问题,我通过在开发环境中禁用缓存来解决它。 我认为缓存不适用于资产即时编译

答案 3 :(得分:1)

我遇到了与-v 3.2.5类似的问题。

经过几个小时的调试,我提出了一个解决方法。它不是很好,但它让我感动,直到我能解决它,或者其他人有更好的运气!

我很好奇这个解决方法是否适合你,Gregory ......

在config / application.rb中,我必须显式添加资产的加载路径......所以:

config.assets.paths << Rails.root.join("app", "assets", "stylesheets")
config.assets.paths << Rails.root.join("app", "assets", "javascripts")
config.assets.paths << Rails.root.join("vendor", "assets", "stylesheets")
config.assets.paths << Rails.root.join("vendor", "assets", "javascripts")
config.assets.paths << Rails.root.join("lib", "assets", "javascripts")

如果您在引擎中有资产,则还需要明确添加它们。它在-v 3.1.x中运行正常。这个变通方法解决这个问题的事实似乎指向一个错误(当然其他人会在现在找到它)或者3.2.5中的一些配置更改。