8

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.

Terence Ponce
  • 9,123
  • 9
  • 31
  • 37
  • 1
    Did you move gems out from `assets` group in Gemfile? This group is no longer used in Rails 4. – Mike Szyndel Jul 05 '13 at 00:06
  • 1
    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 Jul 05 '13 at 00:37
  • 1
    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 Jul 05 '13 at 00:38
  • No, the opposite. But if Heroku detected compiled assets it would not do it on push. I'm really looking for silly errors here – Mike Szyndel Jul 05 '13 at 00:46
  • Do you have any cache enabled? Maybe manifest file got cached? – Mike Szyndel Jul 05 '13 at 00:46
  • As far as I know, I don't think I have caching enabled. I'm actually looking for silly errors as well since I'm fairly certain that I've done everything instructed by Heroku properly. – Terence Ponce Jul 05 '13 at 00:56
  • Heroku enables Rack::Cache by default! Check it with `rake middleware` – Mike Szyndel Jul 05 '13 at 06:43
  • 2
    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 Jul 05 '13 at 11:04
  • Hi, I have been upgrading my rails 3.2 application to rails 4, I have read your question and I'm getting the same problem with app assets. I can see the compiled files under public/assets on heroku but for some reason when I try to access them from the browser, they seem to be empty. have you had any progress? – Alexander Giraldo Jul 16 '13 at 14:12
  • @AlexanderGiraldo I dropped it. I was wasting a lot of time upgrading, so I just went back to 3.2 – Terence Ponce Jul 16 '13 at 23:48
  • @AlexanderGiraldo did you manage to make it work? thanks! – yorch Oct 07 '13 at 12:31
  • You can have a look at this discussion on Stackoverflow - [enter link description here][1] [1]: http://stackoverflow.com/questions/16271696/cant-get-css-working-on-heroku-using-rails-4-with-bootstrap-saas-gem – Himadri Ganguly Mar 17 '14 at 12:41

4 Answers4

1

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.

Mike Szyndel
  • 10,461
  • 10
  • 47
  • 63
0

Using a version for less worked for me

gem 'twitter-bootstrap-rails', '= 2.2.6'
gem 'less-rails', '2.3.3'
Nishant
  • 2,975
  • 23
  • 38
bhagwans
  • 163
  • 1
  • 10
0

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.

Stan Wiechers
  • 1,962
  • 27
  • 45
-3

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

Matt
  • 100
  • 8
  • 1
    This means assets will compile on demand and not make use of precompilation. They will be cached but that is not as fast as precompiling. – joshs Sep 26 '13 at 01:23