user2369480
user2369480

Reputation:

Rails production dont show background images

My images not showed in production (link here).

My code:

_header.html.erb

<%if action_name == 'index' %>
  <div class="main_header_bg" id="main_head">
  <% end %>
   <header id='header'>
    <div class="container">
     <div class="logo">
      <%= link_to image_tag('logo.png'), root_path%>
  </div>

main.css

.main_header_bg {
background-image: url(/header_bg.jpg);
-webkit-background-size: 100% 100%;
background-size: 100% 100%;
height: 718px;

production.log

ActionController::RoutingError (No route matches [GET] "/assets/images/header_bg.jpg"):

Images directories:

  1. app/assets/images/
  2. public/assets/images/

Upvotes: 1

Views: 55

Answers (2)

JackHasaKeyboard
JackHasaKeyboard

Reputation: 1665

Did you precompile your assets? Explicitly in the production environment? This is a very typical issue to run into with people that are pushing Rails projects into production for the first time.

If not, run the following: RAILS_ENV=production bundle exec rake assets:precompile

Remember that actual files are being written here and you'll need to re-upload your application for the changes to take effect.

Upvotes: 1

j-dexx
j-dexx

Reputation: 10406

It's probably because of the asset pipeline

.main_header_bg {
  background-image: image-url("header_bg.jpg");
  -webkit-background-size: 100% 100%;
  background-size: 100% 100%;
  height: 718px;
}

So change url to image-url and precompile and restart the site.

Upvotes: 0

Related Questions