8
votes

I recently tried upgrading my Rails 3.2.13 app to the newly released 4.0.0 and tried deploying it to Heroku. Unfortunately, despite following this guide, the assets still don't seem to precompile properly. Of course, I added the rails_12factor gem already and I also did a couple of things to properly upgrade the app to 4.0.0. It works very nicely on development mode and all my tests are still passing. However, it still doesn't display the assets in Heroku.

One thing I noticed from running heroku run ls public/assets is that Heroku was actually able to precompile the assets from app/assets and doing a cat command on those files will display the compiled version of the assets. However, if I access the file on the browser, I always get a 404.

Is Heroku actually ready for Rails 4?

EDIT:

Here's a list of things I did to upgrade from 3.2.13 to 4:

  • Removed asset group as it is no longer used in Rails 4

  • Update version of rails from 3.2.13 to 4.0.0

  • Remove require line of active_resource/railties from application.rb since active_resource was removed as a dependency from rails

  • Update sass-rails and coffee-rails to use their corresponding master branches because it is using railties 4.0.0.rc2 instead of 4.0.0 as the dependency

  • Update version of devise to 3.0.0.rc

  • Add protected_attributes to ease the transition to Rails 4 without having to switch to strong_parameters yet

  • Change environment configs to add config.eagerload and remove config.whiny_nils to remove deprecation warnings.

  • Change syntax of confirm() to remove deprecation warnings

  • Change hash syntax from hash rockets to the 1.9.3 syntax

  • Remove auto explain config to remove deprecation warnings

  • Add bin directory using rake rails:update:bin

  • Add rails_12factor gem to be able to host to heroku

  • Add ruby version in Gemfile for heroku

EDIT 2

I guess it's also worth mentioning that there wasn't any errors in Heroku during the precompilation and it actually says that it was successful in precompiling the assets which is why it's strange that it didn't work.

4
Did you move gems out from assets group in Gemfile? This group is no longer used in Rails 4.Mike Szyndel
Ok, another wild guess. You don't have assets compiled in public/assets/production in git repo? (asking dumb questions as it looks you took care of everything else)Mike Szyndel
Are you saying I should precompile the assets locally and have it checked into git? Isn't Heroku supposed to precompile the assets upon deployment? At least, that's what it has been doing for me when I was still on 3.2.13.Terence Ponce
No, the opposite. But if Heroku detected compiled assets it would not do it on push. I'm really looking for silly errors hereMike Szyndel
I ran rake middleware. Rack::Cache isn't being used. I tried creating a new Rails 4 app and deployed it to Heroku. For some reason, the assets are being compiled properly in the new app. I'll probably look at the differences between the two.Terence Ponce

4 Answers

1
votes

Try moving all gems from assets group in Gemfile to main scope. Assets group is no longer used in Rails 4 and that may be causing the problem.

0
votes

Using a version for less worked for me

gem 'twitter-bootstrap-rails', '= 2.2.6'
gem 'less-rails', '2.3.3'
0
votes

I run into the same problem. I am now precompiling them locally

bundle exec rake assets:precompile RAILS_ENV=production

and add them to the repository and push them to heroku.

-3
votes

In your production.rb file, make sure that you have the line config.assets.compile = true. That solved the issue for me.