Search code examples
ruby-on-railsrubyherokuassetsprecompile

Heroku not compiling images in a sub folder


Just deployed my app to heroku and had the "Something went wrong" page appear (500 Internal Server Error).

After checking the logs I can see the error comes from this

ActionView::Template::Error (./slider/new_york_2.jpg isn't precompiled):

Within assets/images i have another folder called slider which is for all my images that are in the slider ( trying to keep things organised).

In my view i then display the image like so

<%= image_tag('./slider/new_york_2.jpg') %>

This works in development but not in production it seems.. Am i making a silly mistake anywhere or does heroku specifically not see images in sub fodlers? Im guessing it has something to do with the path structure though?

Any help appreciated


Solution

  • Several possibilities here:


    Path

    You're using a relative path

    You say it's in a view - view paths are based on the assets/images folder. So it can't be relative, as it already is. I would recommend removing the relative path, and basing it on the assets/images folder structure, like this:

    <%= image_tag('slider/new_york_2.jpg') %>
    

    Precompile

    If you're using Heroku, you have to precompile your assets

    This keeps consistency & is quite simple to do:

    #config/production.rb
    config.serve_static_assets = true
    

    Then when you deploy to Heroku, you should do this:

    rake assets:precompile RAILS_ENV=production
    

    This should help!