Image displayed as blank in Rails 3.1 in production (Heroku)

I recently updated Rails to version 3.1.

Here is the part where I added:

<%= asset_path('logo_symbol.png') %> 

This displays /assets/logo_symbol.png , which works fine in a development environment. However, when I click the creation code on the hero, it shows a broken image with the URL: assets/logo_symbol-135ddc8db2c9b59f032bed7db520137a.png . I assume that the new name is associated with some optimization.

However, it is interesting to note that when I go to assets/logo_symbol-135ddc8db2c9b59f032bed7db520137a.png url on production, I see a blank page, but when I change this url to something random, for example, adding numbers to it, it shows the page not found, It is so clear that he finds something at this url. It also shows a blank page when I go to /assets/logo_symbol.png directly to production / heroku.

If this is any help, the hero will not be precompiled successfully when I click on the code, and heroku documentation says that there is currently no work for this problem.

Any help on this would be greatly appreciated.

I suppose this has something to do with some environment related configuration. I am adding the contents of my application.rb, development.rb and production.rb files

here is the contents of my production.rb file

  # Settings specified here will take precedence over those in config/application.rb # In the development environment your application code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.cache_classes = false # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false # Don't care if the mailer can't send #config.action_mailer.default_url_options = { :host => 'localhost:3000' } #config.action_mailer.default_url_options = { :host => 'localhost:3000' } config.action_mailer.delivery_method = :smtp # Print deprecation notices to the Rails logger config.active_support.deprecation = :log # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin # Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true end module ActiveAdmin class Reloader def attach! end end end 

and here is the contents of my development.rb file

  # Settings specified here will take precedence over those in config/application.rb # In the development environment your application code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.cache_classes = false # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false # Don't care if the mailer can't send #config.action_mailer.default_url_options = { :host => 'localhost:3000' } #config.action_mailer.default_url_options = { :host => 'localhost:3000' } config.action_mailer.delivery_method = :smtp # Print deprecation notices to the Rails logger config.active_support.deprecation = :log # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin # Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true end module ActiveAdmin class Reloader def attach! end end end 

Here is the contents of my production.rb file

  # Settings specified here will take precedence over those in config/application.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_controller.perform_caching = true # Specifies the header that your server uses for sending files config.action_dispatch.x_sendfile_header = "X-Sendfile" # For nginx: # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # If you have no front-end server that supports something like X-Sendfile, # just comment this out and Rails will serve the files # See everything in the log (default is :info) # config.log_level = :debug # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Use a different cache store in production # config.cache_store = :mem_cache_store # Disable Rails static asset server # In production, Apache or nginx will already do this config.serve_static_assets = false # Enable serving of images, stylesheets, and javascripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false #config.action_mailer.default_url_options = { :host => 'ha1.heroku.com' } config.action_mailer.delivery_method = :smtp # Enable threaded mode # config.threadsafe! # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true # Send deprecation notices to registered listeners config.active_support.deprecation = :notify # Compress JavaScripts and CSS #config.assets.compress = true # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false # Generate digests for assets URLs config.assets.digest = true # Defaults to Rails.root.join("public/assets") # config.assets.manifest = YOUR_PATH config.assets.js_compressor = :uglifier config.assets.css_compressor = :scss 

I have mapped my configuration files with the rails documentation for 3.1 and it looks like I need all the defaults. However, I still do not see the image. Any help would be greatly appreciated

+7
source share
2 answers

Remove this line from production.rb:

  config.action_dispatch.x_sendfile_header = "X-Sendfile"

You must also align the settings in your configuration files with the sections in section 9 of the pipeline manuals .

Sendfile headers contain information for the upstream web server, where you can find the file (in the file system) to serve it. This removes the load from the backend (Rails / Sprockets). When sendfile is in the HTTP response, there is no body (this is zero length), so you can’t see anything.

In Heroku, nginx servers do not have access to the application file system, so this will not work.

See this note on the geoku dev refile website.

If you use a hero, this document describes the best options for efficient use of the conveyor.

+13
source

You need to do two things to solve this problem. First, change these two lines from false to true in the production.rb file.

  config.assets.compile = true config.assets.digest = true 

Secondly, if you have this syntax for your images

  background: url("imgo.jpg") 

Change it to

  background: image-url("image.jpg") 

I hope this works.

0
source

All Articles