title: Rails - Asset is not present in asset pipeline when using image_tag
body: <p>Goal: Using my rails app with static images in assets in production environemt</p>
  
  <p>Steps:</p>
  
  <ol>
  <li>I turned my rails app to production environment.</li>
  <li>Precompiled the assets with <code>RAILS_ENV=production rails assets:precompile</code></li>
  <li>Set <code>RAILS_SERVE_STATIC_FILES</code> environemt variable to <code>true</code> to enable   public file server (in <code>production.rb</code> - <code>config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?</code></li>
  <li>Added line <code>config.serve_static_assets = true</code> to
  <code>/config/application.rb</code></li>
  </ol>
  
  <p>With this setup, I`ve started the server.</p>
  
  <p>I have a few static images in <code>/app/assets/images/</code> which precompiled versions with fingerprint filename are now in <code>/public/assets</code>. Examples:</p>
  
  <ul>
  <li><code>aussen-d2fb0029a12281121a1752c599e715a8e2b3db17f1e8e18248a79a7b1ca63b91.jpg</code></li>
  <li><code>hintergrund-ca80e1ae5a697c86898f3a7e107694a76dc12e54320b8ac80c58eecbffe0414a.png</code></li>
  </ul>
  
  <p>So far so great.</p>
  
  <p>When I use <code>background-image: url(&lt;%= asset_path('hintergrund') %&gt;);</code> in <code>application.css.erb</code> it successfully loads the precompiled background-image from <code>/public/assets</code>.</p>
  
  <p><strong>Problem:</strong> I can't access the precompiled images with my image_tags in the views! Example:</p>
  
  <pre><code>&lt;%= image_tag("aussen") %&gt;
  </code></pre>
  
  <p>Error Logs:</p>
  
  <pre><code>I, [2018-03-23T00:46:29.133381 #9289]  INFO -- : [f36ff000-6261-4c2c-bfcc-4a2f80cae682] Started GET "/" for 46.142.136.81 at 2018-03-23 00:46:29 +0100
  I, [2018-03-23T00:46:29.134466 #9289]  INFO -- : [f36ff000-6261-4c2c-bfcc-4a2f80cae682] Processing by HomeController#index as HTML
  I, [2018-03-23T00:46:29.136604 #9289]  INFO -- : [f36ff000-6261-4c2c-bfcc-4a2f80cae682]   Rendering home/index.html.erb within layouts/application
  I, [2018-03-23T00:46:29.138267 #9289]  INFO -- : [f36ff000-6261-4c2c-bfcc-4a2f80cae682]   Rendered home/index.html.erb within layouts/application (1.5ms)
  I, [2018-03-23T00:46:29.138482 #9289]  INFO -- : [f36ff000-6261-4c2c-bfcc-4a2f80cae682] Completed 500 Internal Server Error in 4ms
  F, [2018-03-23T00:46:29.139546 #9289] FATAL -- : [f36ff000-6261-4c2c-bfcc-4a2f80cae682]
  F, [2018-03-23T00:46:29.139635 #9289] FATAL -- : [f36ff000-6261-4c2c-bfcc-4a2f80cae682] ActionView::Template::Error (The asset "aussen" is not present in the asset pipeline.):
  F, [2018-03-23T00:46:29.139798 #9289] FATAL -- : [f36ff000-6261-4c2c-bfcc-4a2f80cae682]     1: &lt;%= image_tag("aussen", id: "home-img", alt: "Aussenansicht von Simson-Seelig") %&gt;
  [f36ff000-6261-4c2c-bfcc-4a2f80cae682]     2: &lt;div id="home" class="content"&gt;
  [f36ff000-6261-4c2c-bfcc-4a2f80cae682]     3:   &lt;p&gt;Alles für Simson von Simson-Seelig.&lt;/p&gt;
  [f36ff000-6261-4c2c-bfcc-4a2f80cae682]     4:   &lt;p&gt;Für die legendären Schwalben und alle anderen SIMSON-Modelle bieten wir Ersatzteile und Service. &lt;/p&gt;
  F, [2018-03-23T00:46:29.139867 #9289] FATAL -- : [f36ff000-6261-4c2c-bfcc-4a2f80cae682]
  F, [2018-03-23T00:46:29.139930 #9289] FATAL -- : [f36ff000-6261-4c2c-bfcc-4a2f80cae682] app/views/home/index.html.erb:1:in `_app_views_home_index_html_erb__177499641769
  </code></pre>
  
  <p>After hours of researching, I still don't get why I can access the precompiled image in the stylesheet, but not in the view with the image_tag.</p>
  
  <p>Additional information:</p>
  
  <pre><code>$ ruby --version
  ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-linux]
  
  $ rails --version
  Rails 5.1.4
  </code></pre>
  
  <p><code>/config/application.rb</code>:</p>
  
  <pre><code>require_relative 'boot'
  
  require 'rails/all'
  
  # Require the gems listed in Gemfile, including any gems
  # you've limited to :test, :development, or :production.
  Bundler.require(*Rails.groups)
  
  module SimsonSeelig
    class Application &lt; Rails::Application
      # Initialize configuration defaults for originally generated Rails version.
      config.load_defaults 5.1
  
      # Settings in config/environments/* take precedence over those specified here.
      # Application configuration should go into files in config/initializers
      # -- all .rb files in that directory are automatically loaded.
  
      # Enable rails to serve my assets
      config.serve_static_assets = true
    end
  end
  </code></pre>
  
  <p><code>production.rb</code>:</p>
  
  <pre><code>Rails.application.configure do
    # Settings specified here will take precedence over those in config/application.rb.
  
    # Code is not reloaded between requests.
    config.cache_classes = true
  
    # Eager load code on boot. This eager loads most of Rails and
    # your application in memory, allowing both threaded web servers
    # and those relying on copy on write to perform better.
    # Rake tasks automatically ignore this option for performance.
    config.eager_load = true
  
    # Full error reports are disabled and caching is turned on.
    config.consider_all_requests_local       = false
    config.action_controller.perform_caching = true
  
    # Attempt to read encrypted secrets from `config/secrets.yml.enc`.
    # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
    # `config/secrets.yml.key`.
    config.read_encrypted_secrets = true
  
    # Disable serving static files from the `/public` folder by default since
    # Apache or NGINX already handles this.
    config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
  
    if ENV["RAILS_LOG_TO_STDOUT"].present?
      logger           = ActiveSupport::Logger.new(STDOUT)
      logger.formatter = config.log_formatter
      config.logger = ActiveSupport::TaggedLogging.new(logger)
    end
  
    # Compress JavaScripts and CSS.
    config.assets.js_compressor = :uglifier
    # config.assets.css_compressor = :sass
  
    # Do not fallback to assets pipeline if a precompiled asset is missed.
    config.assets.compile = false
  
    # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
  
    # Enable serving of images, stylesheets, and JavaScripts from an asset server.
    # config.action_controller.asset_host = 'http://assets.example.com'
  
    # Specifies the header that your server uses for sending files.
    # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
    # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
  
    # Mount Action Cable outside main process or domain
    # config.action_cable.mount_path = nil
    # config.action_cable.url = 'wss://example.com/cable'
    # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
  
    # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
    # config.force_ssl = true
  
    # Use the lowest log level to ensure availability of diagnostic information
    # when problems arise.
    config.log_level = :debug
  
    # Prepend all log lines with the following tags.
    config.log_tags = [ :request_id ]
  
    # Use a different cache store in production.
    # config.cache_store = :mem_cache_store
  
    # Use a real queuing backend for Active Job (and separate queues per environment)
    # config.active_job.queue_adapter     = :resque
    # config.active_job.queue_name_prefix = "simson-seelig_#{Rails.env}"
    config.action_mailer.perform_caching = false
  
    # Ignore bad email addresses and do not raise email delivery errors.
    # Set this to true and configure the email server for immediate delivery to raise delivery errors.
    # config.action_mailer.raise_delivery_errors = false
  
    # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
    # the I18n.default_locale when a translation cannot be found).
    config.i18n.fallbacks = true
  
    # Send deprecation notices to registered listeners.
    config.active_support.deprecation = :notify
  
    # Use default logging formatter so that PID and timestamp are not suppressed.
    config.log_formatter = ::Logger::Formatter.new
  
    # Use a different logger for distributed setups.
    # require 'syslog/logger'
    # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
  
    if ENV["RAILS_LOG_TO_STDOUT"].present?
      logger           = ActiveSupport::Logger.new(STDOUT)
      logger.formatter = config.log_formatter
      config.logger    = ActiveSupport::TaggedLogging.new(logger)
    end
  
    # Do not dump schema after migrations.
    config.active_record.dump_schema_after_migration = false
  end
  </code></pre>
  
  <p><code>/config/initializers/assets.rb</code>:</p>
  
  <pre><code># Be sure to restart your server when you modify this file.
  
  # Version of your assets, change this if you want to expire all your assets.
  Rails.application.config.assets.version = '1.0'
  
  # Add additional assets to the asset load path.
  # Rails.application.config.assets.paths &lt;&lt; Emoji.images_path
  # Add Yarn node_modules folder to the asset load path.
  Rails.application.config.assets.paths &lt;&lt; Rails.root.join('node_modules')
  
  # Precompile additional assets.
  # application.js, application.css, and all non-JS/CSS in the app/assets
  # folder are already added.
  # Rails.application.config.assets.precompile += %w( admin.js admin.css )
  </code></pre>