0

I'm running the app and everything is working great in development but in production (heroku) I have some troubles with js files (doesn't load jquery properly and make some things to broke).

Are there something that is called differently on production in the assets ? Maybe some files are overriding others when it is compressed in heroku app. I just want to get the same result in both environments.

application.js

//= require jquery
//= require jquery.turbolinks
//= require jquery-ujs/src/rails
//= require jquery-ui
//= require bootstrap-sass/assets/javascripts/bootstrap
...

development.rb

Rails.application.configure do
  config.action_mailer.delivery_method = :letter_opener
  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
  config.cache_classes = false
  config.eager_load = false
  config.consider_all_requests_local = true
  if Rails.root.join('tmp/caching-dev.txt').exist?
    config.action_controller.perform_caching = true
    config.cache_store = :memory_store
    config.public_file_server.headers = {
      'Cache-Control' => 'public, max-age=172800'
    }
  else
    config.action_controller.perform_caching = false
    config.cache_store = :null_store
  end
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_caching = false
  config.active_support.deprecation = :log
  config.active_record.migration_error = :page_load
  config.assets.debug = true
  config.assets.quiet = true
  config.file_watcher = ActiveSupport::EventedFileUpdateChecker
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = {host: "localhost:3000"}
end

production.rb

Rails.application.configure do
  config.cache_classes = true
  config.action_mailer.delivery_method = :smtp
  config.eager_load = true
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = true
  config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
  config.assets.js_compressor = :uglifier
  config.assets.compile = true
  config.log_level = :debug
  config.log_tags = [ :request_id ]
  config.action_mailer.perform_caching = false
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new
  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger = ActiveSupport::TaggedLogging.new(logger)
  end
  config.active_record.dump_schema_after_migration = false
end
Fillype Farias
  • 622
  • 1
  • 8
  • 20
  • Did you precompile your assets before pushing? Make sure to run $ "bundle exec rake assets:precompile RAILS_ENV=production" before doing a git commit and then do a heroku push. Also, why is consider_all_requests_local true in prod.? Also, config.assets.compile SHOULD NEVER BE SET TO TRUE IN PRODUCTION. Are your jquery statements wrapped in the proper "on page load" functions so they're not glitched by turbolinks and wait until the doc is ready? Post your js code. – bkunzi01 Jun 04 '18 at 21:51
  • hi @bkunzi01, thank you for your advice and I made 'consider_all_request_local' to show the errors message (the app is not done yet) and I don't understand why it is not recommended to set true to 'config.assets.compile' if this command on terminal makes the same action? – Fillype Farias Jun 04 '18 at 22:16
  • Here's a good writeup on why you never want to set compile=true in production. https://stackoverflow.com/questions/8821864/config-assets-compile-true-in-rails-production-why-not – bkunzi01 Jun 05 '18 at 12:46

0 Answers0