8

I know that Heroku is running the rake assets:precompile task:

-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
-----> Rails plugin injection
       Injecting rails_log_stdout
       Injecting rails3_serve_static_assets
-----> Discovering process types
       Procfile declares types      -> (none)
       Default types for Ruby/Rails -> console, rake, web, worker
-----> Compiled slug size is 17.7MB
-----> Launching... done

And I told it to precompile images in production.rb

# from: http://stackoverflow.com/questions/8052865/rails-3-1-asset-pipeline-why-my-images-do-not-precompile-for-production
config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif] 

So why do I still get this 500 error?

2012-05-29T02:57:15+00:00 app[web.1]: Started GET "/signin" for 46.114.68.16 at 2012-05-29 02:57:15 +0000
2012-05-29T02:57:15+00:00 app[web.1]: Processing by SessionsController#new as HTML
2012-05-29T02:57:15+00:00 app[web.1]:   Rendered sessions/new.html.erb within layouts/application (25.4ms)
2012-05-29T02:57:15+00:00 app[web.1]: Completed 500 Internal Server Error in 27ms
2012-05-29T02:57:15+00:00 app[web.1]: 
2012-05-29T02:57:15+00:00 app[web.1]: ActionView::Template::Error (twitter_64.png isn't precompiled):
2012-05-29T02:57:15+00:00 app[web.1]:     25: <div id="auths">
2012-05-29T02:57:15+00:00 app[web.1]:     27:   <a href="/auth/twitter" class="provider">
2012-05-29T02:57:15+00:00 app[web.1]:     26:   <h2>Or sign in through one of these:</h2>
2012-05-29T02:57:15+00:00 app[web.1]:     28:     <%= image_tag "twitter_64.png", :size => "64x64", :alt => "Twitter" %>Twitter</a>

Interestingly, I have images on other pages that show just fine. Don't know why some images wouldn't work, but some would...

Geoff
  • 9,470
  • 13
  • 52
  • 67

2 Answers2

7

First, be sure you have this set as well:

config.assets.initialize_on_precompile = false

If that doesn't work, it's worth trying to manually run the precompile task before building the slug; I think there are subtle differences when done this way:

RAILS_ENV=production bundle exec rake assets:precompile

Last, it's not a solution, but if all else fails, a temporary workaround would be to set

config.assets.compile = true
Darshan Rivka Whittle
  • 32,989
  • 7
  • 91
  • 109
  • Thanks for this, running `RAILS_ENV=production bundle exec rake assets:precompile` before pushing worked for me. – Jason Feb 15 '13 at 06:58
2

Make sure you are putting your images in

app/assets/images

and not in

public/assets

directly.

Then run rake assets:precompile and see if it improves. It can get a bit confusing.

mjnissim
  • 3,102
  • 1
  • 19
  • 22
  • this copies the images into the public directory. Do you delete the images from the app/assets/images directory once they've been added to the public directory. Also having trouble with how to reference the files. Should I be using their normal name or the stars-xxxx.jpg name. – flobacca Nov 14 '13 at 15:28
  • 1
    1) You don't have to use the weird names they get from the Rails system, just their normal names. If they're in a subfolder, just give their relative path, otherwise not even that. It knows what to do. 2) No, don't delete the app/assets/images directory when they've been copied. – mjnissim Nov 14 '13 at 18:19