【问题标题】:rake assets:precompile not working on herokurake 资产:预编译不适用于 heroku
【发布时间】:2012-04-04 23:26:54
【问题描述】:

我的网站过去可以正常工作,Heroku 预编译了资产和所有内容。现在,似乎不知从何而来,我开始在部署时获得rake aborted! stack level too deep

从我的 application.css 文件中删除行 *= require_tree . 似乎可以修复stack level too deep 但后来我得到了这个:

Running: rake assets:precompile
(in /tmp/build_b8o2t4k8frce)
/usr/local/bin/ruby /tmp/build_b8o2t4k8frce/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
(in /tmp/build_b8o2t4k8frce)

我所有的图片链接都已损坏(我在我的 css 文件中使用了 image-url())。可能是什么问题,我该如何解决?

我正在使用 cedar 堆栈,这是我的 gemfile:

gem 'rails', '3.1.0'
gem 'rake', '0.8.7'
gem 'devise'

group :production do
  gem 'pg'
  gem 'thin'
end

group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end

这里是heroku使用的版本:

Using rake (0.8.7)
Using rails (3.1.0)
Using sass (3.1.15)
Using sass-rails (3.1.6)

这是我的 application.rb 文件

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require *Rails.groups(:assets => %w(development test))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

module App
  class Application < Rails::Application

    # Enable the asset pipeline
    config.assets.enabled = true

    # Version of your assets, change this if you want to expire all your assets.
    config.assets.version = '1.0'
  end
end

这是我的 production.rb 文件

# Full error reports are disabled and caching is turned on
config.consider_all_requests_local       = false
config.action_controller.perform_caching = true

# Enable Rails's static asset server (Apache or nginx will not need this)
config.serve_static_assets = true

# Set expire header of 30 days for static files
config.static_cache_control = "public, max-age=2592000"

# Allow JavaScript and CSS compression
config.assets.compress = true

# Compress JavaScript by removing whitespace, shortening variable names, ...
config.assets.js_compressor = :uglifier

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true

# Generate digests for assets URLs
config.assets.digest = true

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 heroku


    【解决方案1】:

    您不必从 application.css 中删除此 *= require tree .,因为它会加载您所有的样式。只需添加它,然后像这样配置您的config/production.rb 文件:

    config.assets.precompile = %w{application.js}
    

    并运行 RAILS_ENV=production rake assets:precompile

    编辑 尝试使用此配置:

    config.assets.digest  = true
    

    【讨论】:

    • 是的,这应该适用于require_tree,但如果我添加它,我会得到rake aborted! stack level too deep。我不知道这是怎么发生的
    • 对不起,我忘了复制那行,我已经在使用摘要了。我找到了一个解决方法,虽然我不太喜欢它
    【解决方案2】:

    显然 sass 停止工作,我失去了耐心,所以我决定不再使用它。而不是这样做:

    #theme.css.scss
    background-image:image-url('image.png');
    

    现在我只是在使用 erb 文件:

    #theme.css.erb
    background-image:url(<%= asset_path 'image.png' %>);
    

    我因此失去了一整天,我不知道为什么,因为它昨天工作得很好。如果有人知道是什么原因造成的以及我如何再次使用 sass,请发表评论。

    【讨论】:

    • 我注意到在某些使用 sass 的环境中,如果 ':' 和我的语句中的值之间没有空格,我会收到错误消息,所以不要写类似“background-image:image-url('图像.png')";写 "background-image: image-url('image.png')" [注意 ':' 后面的空格]
    【解决方案3】:

    我遇到了类似的问题,在这里找到了答案:https://github.com/rails/sass-rails/issues/78。基本上,降级到 sass-rails v3.1.4。希望这会有所帮助

    【讨论】:

    • 哇,就是这样!那解决了它!问题是,我是一个新手,我认为这条线 gem 'sass-rails', "~&gt; 3.1.0" 意味着我的 gem 版本已被锁定,但显然那个波浪形的 hashrocket(或任何它的名字)让我们更新 gem。也许这就是发生的事情,也许 Heroku 在内部改变了一些东西,突然我的应用程序停止了工作。真的很奇怪,让我白白浪费了一整天。对于可能最终出现在这里的任何人,解决方案是将该行更改为gem 'sass-rails', "3.1.4"
    • 谢谢 - 大帮助 - 同样的问题,不知从何而来。这是我今天需要看到的最后一件事是 push to heroku 失败。
    猜你喜欢
    • 1970-01-01
    • 2023-04-09
    • 2014-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多