Ruby on Rails: Ran rake assets:precompile and now both local and heroku deployment don't include bootstrap

狂风中的少年 提交于 2019-12-24 19:08:37

问题


I was having issues deploying my project to a heroku server (Precompile fail). So I found this response, https://stackoverflow.com/a/13713753/2989437, and followed up on the advice. I added one line to my application.rb file:

application.rb

module FirstEdc
  class Application < Rails::Application
    config.assets.initialize_on_precompile = false # I added this line
  ...
 end
end

I then ran the precompile command, committed the changes, and managed to deploy successfully to heroku. However, now my bootstrap/css appears to have stopped functioning both on the heroku deployment, and my local deployment.

I learned that I was supposed to add another line to my deployment.rb file:

deployment.rb

FirstEdc::Application.configure do
  ...

  # Allows for local precompilling --added by Ian
  config.assets.prefix = '/dev-assets'
end

So I added this, recompiled and redeployed, but to no avail.

Finally, I ran a rake assets:clean in an attempt to at least get my local deployment back to normal, but it did not work.

Any advice would be greatly appreciated. I'm reading more into the asset pipeline now, but I feel like this could be a cache problem or something. I'll update as I figure out what's going on.

edit. Just to clarify, I've tried removing both additions, running a rake assets:clean and rake assets:clean:all, but neither fix my local deployment.


回答1:


I don't use config.assets.prefix in any of my apps and they work just fine with Heroku, so not sure what that's doing.

Try removing that line, then running rake assets:clean. Now your local server should be using the files as you change them. When you want to push, run rake assets:precompile first, then push.

If you want to make changes locally after that, run rake assets:clean again to get rid of the precompiled files on your local machine.




回答2:


If Heroku detects any files in public/assets it will not attempt to precompile your assets again. This is by design.

So, you need to make a decision to either always precompile your assets with rake assets:precompile, or remove any files in public/assets before pushing to Heroku.

(The recommended way is to allow Heroku to precompile them during push)



来源:https://stackoverflow.com/questions/20685924/ruby-on-rails-ran-rake-assetsprecompile-and-now-both-local-and-heroku-deployme

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