问题 Rails资产预编译只是不起作用


我已经将Rails应用程序推送到Heroku并继续遇到以下问题:

我将更改保存到我的主css.scss文件(在资产/样式表中)或资产/图像中的图像,推送到git,将其推送到heroku,然后重新加载页面,只是发现这些资产没有已装满了。

这也是本地服务器上的一个小问题,但输入:

rake assets:precompile

并重新加载本地服务器通常工作,而做

heroku run rake assets:precompile

然后重新推动什么也没做。我已经四处寻找信息并且没有找到任何特别有帮助的东西。

值得注意的是,在我的 配置/ application.rb中 (其中一些是所说的钓鱼的结果):

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

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

配置/环境/ production.rb

# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false

# Compress JavaScripts and CSS
config.assets.compress = true

# Fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true

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

还有其他可能的兴趣,当我推送到heroku时,除其他外,它说:

Preparing app for Rails asset pipeline
       Detected manifest.yml, assuming assets were compiled locally
-----> Rails plugin injection
       Injecting rails_log_stdout
       Injecting rails3_serve_static_assets

Installing dependencies using Bundler version 1.3.0.pre.5
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment

我学习了Rails 3并且不知道资产管道与先前版本中的资源管道有何不同,所以如果我是一个白痴并在我的配置文件中放置重叠和/或相互矛盾的设置,那就很抱歉。

非常感谢任何帮助。这一直很头疼。


885
2018-02-04 23:24


起源



答案:


看起来可能是你将本地编译的资产添加到git并推送它们,因此Heroku不会在推送时编译你的资产。检查以确保您没有将公共/资产目录添加到git。


13
2018-02-05 00:01



所以你的意思是添加/公共/资产到.gitignore文件?那个AND“git rm”目录?或者删除其中的特定文件?抱歉。我不知道该目录与资产管道有什么关系,所以我不确定如何追溯性地添加其不良组件。 - Sasha
从git中删除该目录,然后将其添加到git ignore中。此目录是运行rake资产时编译所有资产的位置:预编译。 - Karl Baum
确保将public / assets /中已删除的文件提交给master!所以你将一个空的public / assets /目录推送到heroku。你应该看到heroku自动调用rake资产:precompile - Bruno
我们还应该跑吗 RAILS_ENV=production bundle exec rake assets:precompile 在推到Heroku之前? - starscream_disco_party
他的改变也是 application.rb 和 production.rb 真的有必要 public/assets/ 在... .gitignore? - starscream_disco_party


答案:


看起来可能是你将本地编译的资产添加到git并推送它们,因此Heroku不会在推送时编译你的资产。检查以确保您没有将公共/资产目录添加到git。


13
2018-02-05 00:01



所以你的意思是添加/公共/资产到.gitignore文件?那个AND“git rm”目录?或者删除其中的特定文件?抱歉。我不知道该目录与资产管道有什么关系,所以我不确定如何追溯性地添加其不良组件。 - Sasha
从git中删除该目录,然后将其添加到git ignore中。此目录是运行rake资产时编译所有资产的位置:预编译。 - Karl Baum
确保将public / assets /中已删除的文件提交给master!所以你将一个空的public / assets /目录推送到heroku。你应该看到heroku自动调用rake资产:precompile - Bruno
我们还应该跑吗 RAILS_ENV=production bundle exec rake assets:precompile 在推到Heroku之前? - starscream_disco_party
他的改变也是 application.rb 和 production.rb 真的有必要 public/assets/ 在... .gitignore? - starscream_disco_party