Can't (ever) get Rails 3.1 to server assets from asset_host #2504

Closed
matpowel opened this Issue Aug 12, 2011 · 7 comments

Projects

None yet

5 participants

@matpowel

Hi all,

I've had a particularly frustrating night as Heroku appears to always run out of memory trying to compile our assets dynamically and now it seems we just cannot get Rails to honour the asset_host setting.

Here's the important bits of our staging env:

  # 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

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = true

  # Compress both stylesheets and JavaScripts
  config.assets.compress = true
  config.assets.js_compressor  = :uglifier
  config.assets.css_compressor = :yui

  # Specifies the header that your server uses for sending files
  # (comment out if your front-end server doesn't support this)
  config.action_dispatch.x_sendfile_header = nil # nil for Heroku # default "X-Sendfile" # Use 'X-Accel-Redirect' for nginx

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  config.force_ssl = true

  # Use a different cache store in production
  config.cache_store = :file_store, "tmp/cache"

  # Enable serving of images, stylesheets, and JavaScripts from an asset server
  config.action_controller.asset_host = "https://#{configatron.s3_bucket_name}.amazonaws.com"

The assets precompile just fine, we use a nice gem called "asset_sync" which happily uploads them all to S3 for us so they're sitting there waiting..

Things we've tried:

  • Both on Heroku and locally using thin -e staging start (also tried production on local machine)
  • Commenting out the various "compress" options
  • A plain string instead of using configatron for the bucket name

please someone tell us we've missed something obvious :-)

Thanks,
//matt

@matpowel

I did some digging, in the definition of asset_paths the rails sprockets helper does:

module Sprockets
  module Helpers
    module RailsHelper
      extend ActiveSupport::Concern
      include ActionView::Helpers::AssetTagHelper

      def asset_paths
        @asset_paths ||= begin
p self.respond_to?( :config )
          config     = self.config if respond_to?(:config)
          config   ||= Rails.application.config
p config

From those prints I get "true" and an empty UnorderedHash. So one of the gems in our app or an include pattern or some such thing in our app is implementing a "config" method on our view? Am I reading that code right?

If I put the following instead of the 2 setter lines above it all works as expected..

config = Rails.application.config

It seems like a strange monkey patch to have to put in though??

Anyone who knows the code able to comment?

@spastorino
Ruby on Rails member

@josh can you check that?

@jgadbois

Having a similar problem - scss image_path is working, but no asset tags use the asset_host:

#3759

@kennyj

@matpowel
Is this issue related to #2980.
If this is same issue (or same cause of problem), could you close this issue ?
#2980 is fixed by @josevalim

@jgadbois
I think that your mention is another from this issue.
Let us discuss in #3759 !

@steveklabnik
Ruby on Rails member

Is this still a problem? I know there's been lots of changes with the asset pipeline over the last 6 months.

@matpowel

I just checked, we've removed the monkey patch from our initializers so I assume that means it's fixed. Thanks *8)

@matpowel matpowel closed this Apr 30, 2012
@steveklabnik
Ruby on Rails member

Excellent!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment