0

I'm very frustrated as I have a rails application and locally everything works fine. I use some css background images but after deploying on Heroku the css background images were not shown...

I have googled a lot and I know thats a problem with static assets but no solution works for me.

in my css.erb file:

.fade-carousel .slides .slide-1 {
background-image: image-url("ich.jpg");
}
.fade-carousel .slides .slide-2 {
background-image: image-url("gruen.jpg");
}
.fade-carousel .slides .slide-3 {
 background-image: image-url("see.jpg");
}
.fade-carousel .slides .slide-4 {
 background-image: image-url("huette.jpg");
}

I' have added this to my gemfile:

group :production do
  gem 'pg'
  gem 'rails_12factor', '0.0.2'
end

And I have added following to my config/production.rb:

config.serve_static_files = true
config.serve_static_assets = true

But nothing works :(. When I deploy the project to heroku a get no background images and following log message:

 ActionController::RoutingError (No route matches GET]"/images/huette.jpg"):
 ActionController::RoutingError (No route matches GET]"/images/see.jpg"):
 ActionController::RoutingError (No route matches GET]"/images/gruen.jpg"):
 ActionController::RoutingError (No route matches GET]"/images/ich.jpg"):
8
  • did you try running: heroku run rake assets:precompile? Commented Jul 29, 2016 at 12:02
  • Yes I have done: " rake assets:precompile RAILS_ENV=production" before deploying the project. :( Commented Jul 29, 2016 at 12:04
  • 1
    please try: heroku run rake assets:precompile Commented Jul 29, 2016 at 12:05
  • Ok I tried: "heroku run rake assets:precompile" after deploying...unfortunately it dosnt work :( It is necessary to restart the server or something else? Commented Jul 29, 2016 at 12:09
  • I got: Running rake assets:precompile on ypurApp... up, run.6327 I, [2016-07-29T12:06:55.645491 #3] INFO -- : Writing /app/public/assets/application-fa5771c0b7a9267 ad3a01a06468c350c.js I, [2016-07-29T12:06:57.518505 #3] INFO -- : Writing /app/public/assets/app_design-aeffb3c4c2c299ab a9c9136809ddef21.css I, [2016-07-29T12:07:27.799927 #3] INFO -- : Writing /app/public/assets/application-9e6a11106b17172 b5dd0de3ce58b3937.css I, [2016-07-29T12:07:27.928166 #3] INFO -- : Writing /app/public/assets/style-f193a906435cbf40464ab 99c34ed5516.css Commented Jul 29, 2016 at 12:10

1 Answer 1

1

This is the right way to call your images when they are in the asset folder:

.class { background-image: url(<%= asset_path 'image.png' %>) }

Try that and let us know.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.