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

185 views Asked by At

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.

2

There are 2 answers

2
Donovan On

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)

3
Tyler On

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.