title: Rails 4 - Background Image Appears in Localhost but not in production
body: <p>I recently rewrote one of my Rails 3.2.13 applications to use Rails 4.  I used twitter-bootstrap-rails 2.1.2 in my Rails 3 application.  When I rewrote the Rails 4 version it started using version 2.2.8.  I'm using Phusion Passenger 4.0.20 on my development and production servers to host all my Rails applications.</p>
  
  <p>In my Rails 3 application the background image appeared correctly in localhost and in production. However when I rewrote the application using Rails 4 and the current version of twitter-bootstrap-rails I noticed that the background image appears correctly but when I deploy it in production the background image does not display.</p>
  
  <p>I have tried the following CSS but the background image only appears in localhost.  The first statement is the original CSS code that was working well in my Rails 3 application in localhost and production.</p>
  
  <pre><code>background: url(/assets/landingpage2.jpg); width: 574px; height: 650px;
  
  background: url(../assets/landingpage2.jpg); width: 574px; height: 650px;
  
  background-image: url(../assets/landingpage2.jpg); width: 574px; height: 650px;
  
  background-image: url("../assets/landingpage2.jpg"); width: 574px; height: 650px;
  
  background-image: url("/assets/landingpage2.jpg"); width: 574px; height: 650px;
  </code></pre>
  
  <p>Here is the class that includes the background statement that originally worked:</p>
  
  <pre><code>.landing-cube-menu {
    font-weight: bold; 
    font-size: 150%;
    line-height: 100%;    
    background: url(/assets/landingpage2.jpg); width: 574px; height: 650px;
    margin:0 auto;  
  }
  </code></pre>
  
  <p>Here is the code that I am using in my view:</p>
  
  <pre><code>&lt;div class="header-cube-menu" style="position: relative;"&gt;
  
    &lt;div class="header-store" style="position: absolute;"&gt;
      &lt;p&gt;&lt;%= link_to "Online Store", store_path %&gt;&lt;/p&gt;
    &lt;/div&gt;
  
    &lt;div class="header-about" style="position: absolute;"&gt;
      &lt;p&gt;&lt;%= link_to "About", about_path %&gt;&lt;/p&gt;
    &lt;/div&gt;
  
    &lt;div class="header-contact" style="position: absolute;"&gt;
      &lt;p&gt;&lt;%= link_to "Contact", contact_path %&gt;&lt;/p&gt;
    &lt;/div&gt;
  
    &lt;div class="header-verse" style="position: absolute;"&gt;
      &lt;p&gt;&lt;a href="/verse"&gt;Bible&lt;br&gt;Verse&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;
  
    &lt;div class="header-app" style="position: absolute;"&gt;
      &lt;p&gt;&lt;a href="/app"&gt;Mobile&lt;br&gt;&amp;nbsp;&amp;nbsp;App&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;
  
    &lt;div class="header-home" style="position: absolute;"&gt;
      &lt;p&gt;&lt;a href="/home"&gt;Home&lt;br&gt;&amp;nbsp;Page&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;
  
    &lt;div class="header-math" style="position: absolute;"&gt;
      &lt;p&gt;&lt;a href="/math"&gt;The&lt;br&gt;Math&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;
  
    &lt;div class="header-vision" style="position: absolute;"&gt;
      &lt;p&gt;&lt;a href="/vision"&gt;&amp;nbsp;Vision&lt;br&gt;Mission&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;
  
    &lt;div class="header-pendant" style="position: absolute;"&gt;
      &lt;p&gt;&lt;a href="/pendant"&gt;Pendant&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Desk Cross&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;and more&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;
  
    &lt;div class="header-puzzle" style="position: absolute;"&gt;
      &lt;p&gt;&lt;a href="/puzzle"&gt;3D-Puzzle&lt;br&gt;&amp;nbsp;&amp;nbsp;eBook&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>I have cleared the cache in my browser for both localhost and my domain.  I still see the image in localhost but not with the domain.  I have tried using the latest version of Safari, Chrome, Firefox and Opera on my Mac Mini Server.  All of them get the same results.</p>
  
  <p>I could understand this if I was not seeing the background image in localhost.  I did my testing for the Rails 4 app using localhost and assumed that it would work in production.  However after I deployed it the background image was missing.  This is happening on both my production and development servers.  The image file is in app/assets/images on both servers.  </p>
  
  <p>My original code and all the examples I posted here are correct since the image displays in localhost.  I have no clue where to check at this point. I may post this in the Passenger Google Group.  That is the only other variable between localhost and production, especially considering my development server.</p>
  
  <p>UPDATE: I decided to try other possibilities after I posted this.  NOW the background image no longer appears for localhost.  I'm completely frustrated with this.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>UPDATE 10/19/2013 8:05 PM CDT GMT-5</p>
  
  <p>I attempted to implement the <strong>asset_url</strong> solution in my .less file.  Here are the errors I got when I did the <strong>rake assets:precompile RAILS_ENV=production</strong> command </p>
  
  <pre><code>I, [2013-10-19T19:59:05.384878 #69440]  INFO -- : Writing /Users/myusername/Sites/myrailsapp/public/assets/application-f8821f5601f793a09e9373fb397df1b1.js
      rake aborted!
      undefined method `[]' for nil:NilClass
        (in /Users/myusername/Sites/hypercubeoflove_RoR_4/app/assets/stylesheets/application.css)
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/sass_functions.rb:63:in `sprockets_context'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-rails-4.0.0/lib/sass/rails/helpers.rb:23:in `asset_url'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/script/funcall.rb:112:in `_perform'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/script/node.rb:40:in `perform'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/perform.rb:298:in `visit_prop'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/base.rb:37:in `visit'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/perform.rb:100:in `visit'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/base.rb:53:in `map'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/base.rb:53:in `visit_children'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/perform.rb:109:in `block in visit_children'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/perform.rb:121:in `with_environment'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/perform.rb:108:in `visit_children'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/base.rb:37:in `block in visit'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/perform.rb:320:in `visit_rule'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/base.rb:37:in `visit'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/perform.rb:100:in `visit'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/base.rb:53:in `map'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/base.rb:53:in `visit_children'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/perform.rb:109:in `block in visit_children'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/perform.rb:121:in `with_environment'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/perform.rb:108:in `visit_children'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/base.rb:37:in `block in visit'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/perform.rb:128:in `visit_root'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/base.rb:37:in `visit'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/perform.rb:100:in `visit'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/visitors/perform.rb:7:in `visit'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/tree/root_node.rb:20:in `render'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/engine.rb:315:in `_render'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sass-3.2.12/lib/sass/engine.rb:262:in `render'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/sass_compressor.rb:24:in `evaluate'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/context.rb:197:in `block in evaluate'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/context.rb:194:in `each'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/context.rb:194:in `evaluate'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/bundled_asset.rb:25:in `initialize'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/base.rb:377:in `new'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/base.rb:377:in `build_asset'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/index.rb:94:in `block in build_asset'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/caching.rb:58:in `cache_asset'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/index.rb:93:in `build_asset'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/base.rb:287:in `find_asset'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/index.rb:61:in `find_asset'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:211:in `block in find_asset'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:257:in `benchmark'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:210:in `find_asset'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:119:in `block in compile'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:118:in `each'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:118:in `compile'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-rails-2.0.0/lib/sprockets/rails/task.rb:60:in `block (3 levels) in define'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-2.10.0/lib/rake/sprocketstask.rb:146:in `with_logger'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/gems/sprockets-rails-2.0.0/lib/sprockets/rails/task.rb:59:in `block (2 levels) in define'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/bin/ruby_noexec_wrapper:14:in `eval'
      /Users/myusername/.rvm/gems/ruby-2.0.0-p247@mygemset/bin/ruby_noexec_wrapper:14:in `&lt;main&gt;'
      Tasks: TOP =&gt; assets:precompile
      (See full trace by running task with --trace)
  </code></pre>