0
votes

I have a rails 3.2 app on heroku. I have tried everything I can find to try to fix the fact that the javascripts are not loading in production mode. Everything works fine in dev though. Also, when deploying to heroku, the precompiling fails. However, when I look at the source code in prod, I can clearly see the javascripts file (/assets/application-32fdbd115c5d59c7be2876c103063600.js) loading and has content.

I have tried every setting I can think of and have read about. I am not quite sure what to do. Here's my setup currently in production.rb:

config.cache_classes = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_assets = false
  config.assets.compress = false
  config.assets.compile = true
  config.assets.digest = true

  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify

and in environment.rb:

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
App::Application.initialize!

application.rb:

require File.expand_path('../boot', __FILE__)

require "rails/all"

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

module App
  class Application < Rails::Application
config.encoding = "utf-8"

    # Configure sensitive parameters which will be filtered from the log file.
    config.filter_parameters += [:password]

    # Enable escaping HTML in JSON.
    config.active_support.escape_html_entities_in_json = true
config.active_record.whitelist_attributes = true

    # Enable the asset pipeline
    config.assets.enabled = true

    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.0'

and my gemfile:

gem 'rails', '3.2.6'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'pg'
gem 'mysql2'
gem 'thin'
gem 'activerecord-postgresql-adapter'
gem 'devise'
gem 'paperclip', '~> 3.0'
gem 'haml'
gem 'activeadmin'
gem "meta_search", '>= 1.1.0.pre'
gem 'aws-sdk', '~> 1.3.4'
gem 'acts_as_list'
gem 'stripe'
gem 'sass-rails', '~> 3.2.3'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'coffee-rails', '~> 3.2.1'
  gem 'twitter-bootstrap-rails'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

group :development do
  gem 'debugger'
end

nothing I do seems to get it to work on production mode on my local machine or on heroku. however, it works just fine in development.

2
Have you tried restarting Heroku? heroku restartJason Kim

2 Answers

2
votes

I finally figured out how to fix this, although I don't know how good of a fix it is. Basically, the problem was that the compression of the .js files into application.js was causing issues. In production.rb I put this:

  config.serve_static_assets = false

  # Compress JavaScripts and CSS
  config.assets.compress = false

  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = true

  # Generate digests for assets URLs
  config.assets.digest = true

  config.assets.debug = true

this fixed the issue. however, now instead of application.js, it lists all the asset files. i'm not sure if there are any long-term issues with this.

1
votes

On your production box have you tried: RAILS_ENV rake assets:precompile