I have been having this pretty rough time with assets on production. It came down to me trying to override the sprokets helper module to try and see what was up... When I re-wrote it to the following:
module Sprockets
module Rails
module Helper
def compute_asset_path(path, options = {})
It would not run. I tried it in my local environment, and it runs perfectly. Is there a reason the production environment would not allow my assets to render in digest form, but my local environment would? This is related to what this gent was asking...
Rails 4.0.3 generating incorrect asset paths with asset_sync
Here is the error I receive after trying to override that method (which doesn't have an error when running with RAILS_ENV=development):
ActionView::Template::Error (undefined local variable or method `digest_path' for #<#<Class:0x000001034a99e0>:0x000001034a81d0>):
Asset Gems in Gemfile for reference:
source 'http://rubygems.org'
# ruby '2.1.1'
gem 'rails', '4.0.4'
gem 'jbuilder', '~> 1.2'
gem 'devise'
gem 'devise_invitable'
gem 'figaro'
gem 'mysql2'
gem 'simple_form'
gem 'kaminari'
gem 'statistics'
gem 'possessive'
gem 'geocoder'
gem 'nokogiri'
gem 'asset_sync'
gem 'sprockets-rails', :require => 'sprockets/railtie'
gem 'ledermann-rails-settings', :require => 'rails-settings'
gem 'public_activity'
group :assets do
gem 'therubyracer'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
end
group :development do
gem 'better_errors'
gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx]
gem 'guard-bundler'
gem 'guard-rails'
gem 'quiet_assets'
gem 'rails_layout'
gem 'rb-fchange', :require=>false
gem 'rb-fsevent', :require=>false
gem 'rb-inotify', :require=>false
end
group :test do
gem 'email_spec', '>= 1.4.0'
gem 'launchy', '>= 2.2.0'
gem 'capybara', '>= 2.0.3'
gem 'database_cleaner', '>= 1.0.0.RC1'
gem 'cucumber-rails', '>= 1.3.1', :require => false
end
group :production do
gem 'rails_12factor'
end
gem 'rspec-rails', '>= 2.12.2', :group => [:development, :test]
gem 'factory_girl_rails', '>= 4.2.0', :group => [:development, :test]
gem 'teaspoon', '>= 0.7.4', :group => [:development, :test]
gem 'cancan', '>= 1.6.9'
gem 'rolify', '>= 3.2.0'
gem 'stripe-rails'
gem 'faker'
gem 'open4'
gem 'unf'
When I run this in development mode, it runs completely fine. When I run this through production mode (even with the same config file) it does not inherit the View properties like digest_path
or asset_digest_path
is null or manifest
, etc.
module Sprockets
module Rails
module Helper
def compute_asset_path(path, options = {})
if digest_path = asset_digest_path(path)
path = digest_path if true # BUG: digest assets doesn't work on live, let's just bake it
path += "?body=1" if options[:debug]
File.join(assets_prefix || "/", path)
else
super
end
end
def asset_digest_path(path, options = {})
if manifest = assets_manifest
if digest_path = manifest.assets[path]
return digest_path
end
end
if environment = assets_environment
if asset = environment[path]
return asset.digest_path
end
end
end
end
end
end
module ActionView
module Helpers
module AssetUrlHelper
def compute_asset_path(source, options = {})
dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || ""
File.join(dir, source)
end
end
end
end