Rails Assets Precompile just not working

对着背影说爱祢 提交于 2019-12-29 06:46:29

问题


I've pushed a Rails app to Heroku and keep on running into the following problem:

I'll save changes to my main css.scss file (in assets/stylesheets) or to images in assets/images, push to git, push that to heroku, and reload the page, only to find out that these assets haven't been loaded at all.

This was also a slight problem on the local server, but entering:

rake assets:precompile

and reloading the local server usually worked, whereas doing

heroku run rake assets:precompile

and then re-pushing does nothing. I've fished around for info and haven't found anything particularly helpful.

Of note, in my config/application.rb (some of these the result of said fishing around):

# 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

in config/environments/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

Of additional possible interest, when I push to heroku, it says, among other things, this:

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

and

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

I learned with Rails 3 and don't really know how the assets pipeline differs from what was available in previous version, so sorry if I'm being an idiot and putting overlapping and/or contradictory settings in my config files.

Would appreciate any help. This has been a headache.


回答1:


It looks like it could be that you are add your locally compiled assets to git and pushing them and as a result Heroku is not compiling your assets on push. Check to make sure you are not adding the public/assets directory to git.



来源:https://stackoverflow.com/questions/14697604/rails-assets-precompile-just-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!