I've got a rails app that's driving me crazy. I can't figure out why I'm getting duplicate js calls. I'm guessing it's something to do with the ordering or organization of the application.js require statements and the location of the .js files. I've also tried screwing around with production.rb and usually only make the .js completely broken with that. Here's what I've got:
app
|assets
||javascripts
|||+data_centers
|||-data_center.js
||-application.js
||-rails.js
vendor
|assets
||javascripts
||-autocomplete-rails.js
||-jquery-1.9.1.js
||-jquery-ui-1.10.2.custom.js
application.js has the following require statements:
//= require jquery-1.9.1
//= require jquery-ui-1.10.2.custom
//= require twitter/bootstrap
//= require bootstrap-typeahead
//= require rails
//= require autocomplete-rails
data_center.js has the following require statements:
//= require highcharts
//= require highcharts/modules/canvas-tools
//= require highcharts/modules/exporting
Before, I had the .js files from vendor/assets in app/assets but was advised to keep all external .js in the vendor/assets location. Point is that doesn't work.
My production.rb looks like this:
MyApp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# 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
#default 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
#defualt false
# Compress JavaScripts and CSS
config.assets.compress = false
#defualt true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
#default = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = '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
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# config.assets.precompile += %w( jquery.js )
# config.assets.precompile += %w( jquery_ujs.js )
# config.assets.precompile += %w( jquery-ui-1.10.2.custom.js )
# config.assets.precompile += %w( twitter/bootstrap.js )
# config.assets.precompile += %w( bootstrap-typeahead.js )
# config.assets.precompile += %w( rails.js )
# config.assets.precompile += %w( autocomplete-rails.js )
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# 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
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
end
Please let me know if you have any ideas. Thanks.
You could try config.assets.debug = true in your production.rb to get a better picture, but I'd suggest first trying to debug problems with assets in development.
Some gems or their dependencies may be loading assets that you might not have been aware of.
In Rails console in the environment you are interested in (i.e. you might need to ssh to the server, etc. and/or set the environment in/before the command):
rails c
you might use the following to get a little more info from Sprockets about current assets:
Rails.application.assets.each_file {|path| begin; Rails.application.assets[path].dependencies.each{|d| puts "#{path} dependencies: /assets/#{d.logical_path}"}; rescue; puts "#{path}"; end}
Then you might look at gem list in your prod environment or look at Gemfile.lock to see what gems bundler is using. Maybe assets are being loaded that you didn't know about.
For asset organization, see the guide.
Also, consider that the guide suggests some different settings than what you are using in your production config, e.g. it suggests using config.assets.compress = true and to set config.serve_static_assets = false and have apache or nginx serve static assets, for performance reasons.
Related
I am in the process of upgrading our product from rails 4.1 to 5.2. I'm hung up on what appears to be an asset pipeline related issue. When I load the app in our browser, I see the following error in the server log and the app is missing all styling and javascript code that it normally has.
DEPRECATION WARNING: The asset application.js" is not present in the asset pipeline.Falling back to an asset that may be in the public folder.
This behavior is deprecated and will be removed.
To bypass the asset pipeline and preserve this behavior,
use the `skip_pipeline: true` option.
When I wget the index.html of the application, I see that all of the images and javascript urls are lacking the fingerprint digest they should have. Interestingly enough, they do have the S3 asset_host we have, so they are in fact being processed by the helpers.
To demonstrate, I have two servers which have identical configurations, but one is running 4.1 and the other 5.2. On both, I am using S3 as an asset_host and digest is turned on. I've run the following commands in their consoles:
=== Rails 4 ===
Loading qatest environment (Rails 4.1.0)
irb(main):001:0> Rails.application.config.action_controller.asset_host
=> "https://redacted.s3.amazonaws.com"
irb(main):002:0> Rails.application.config.assets.digest
=> true
irb(main):003:0> ActionController::Base.helpers.asset_path('application.js')
=> "https://redacted.s3.amazonaws.com/assets/application-042f2014ca329c79c304ab1332557040d3f7b922247202f40c28acc950f30ef8.js"
=== Rails 5 ===
Loading sean environment (Rails 5.2.1)
irb(main):001:0> Rails.application.config.action_controller.asset_host
=> "https://redacted.s3.amazonaws.com"
irb(main):002:0> Rails.application.config.assets.digest
=> true
irb(main):003:0> ActionController::Base.helpers.asset_path('application.js')
=> "https://redacted.s3.amazonaws.com/application.js
As requested, production.rb
require "#{File.dirname(__FILE__)}/includes/s3_assets"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb
config.eager_load = true
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = false
config.log_level = ENV['SHOW_SQL'] != 'false' ? :debug : :info
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
user_name: Rubber.config.email_username,
password: Rubber.config.email_password,
address: Rubber.config.email_server,
port: Rubber.config.email_port,
enable_starttls_auto: true, # detects and uses STARTTLS
authentication: 'login' # Mandrill supports 'plain' or 'login'
}
# 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
# Raise exception on mass assignment protection for Active Record models
# config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fall back to assets pipelin if a precompiled asset is
# missed.
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
config.assets.enabled = true
# Nginx will serve as an asset proxy to s3, where assets are
# stored.
config.serve_static_assets = false
# instead of bundling the assets, include multiple css style includes
config.assets.debug = true
config.assets.logger = false
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# NB: The exclusion of any protocol in the asset host declaration above will allow browsers to choose the transport mechanism on the fly.
# So if your application is available under both HTTP and HTTPS the assets will be served to match.
configure_s3_assets config
config.action_controller.asset_host = "https://#{Rubber.config.s3_assets_bucket}.s3.amazonaws.com"
config.action_mailer.default_url_options = { :host => Rubber.config.external_host }
config.sequel.search_path = %w(public audit)
end
config/initializers/assets.rb
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path
# Rails.application.config.assets.paths << Emoji.images_path
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )
Rails.application.config.assets.precompile += %w( *.js *.png *.eot *.woff *.ttf *.svg *.gif)
config/environments/includes/s3_assets.rb
def configure_s3_assets(config)
# Do not compress assets
config.assets.compress = false
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Generate digests for assets URLs
config.assets.digest = true
config.assets.enabled = true
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w(
)
# find javascripts/ stylesheets/ -type f | sed 's/\.scss//' | sed 's/\.coffee//' |
# sed 's/^.*\/\///'| sort
# defaults to application.js, application.css
# application.css has home.css ?
config.assets.precompile += %w(
handlebars.js
jquery-1.7.js
json2.js
)
end
After digging around in the sprockets code, I discovered that my list of resolvers was empty. I'm not sure what was missing from my configuration, but I fixed the problem by adding the following to config/application.rb
config.assets.resolve_with = [:manifest] // in production
config.assets.resolve_with = [:manifest, :environment] // in development
Why Rails won't precompile a .js.erb asset?
My config/application.rb:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(:default, Rails.env)
module Sflitmap
class Application < Rails::Application
# these precompile OK
config.assets.precompile += ['edge/edge.1.5.0.min.js', 'edge/ink-falling_edgeActions.js', 'edge/inkAnimationTrigger.js']
# this will not precompile
config.assets.precompile += ['edge/ink-falling_edge.js.erb']
end
end
My config/environments/production.rb:
Sflitmap::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = '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
# Set to :debug to see everything in the log.
config.log_level = :info
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# config.assets.precompile += %w( search.js )
config.assets.precompile += %w( .svg .eot .woff .ttf )
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# 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
# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
end
When I run RAILS_ENV=production rake assets:precompile I get:
- public
-- assets
--- edge
---- edge.1.5.0.min-610ab04bb1d4d0ad9a2a845821f04bdf.js
---- edge.1.5.0.min-610ab04bb1d4d0ad9a2a845821f04bdf.js.gz
---- ink-falling_edgeActions-9bdaa1845a29b15bd2562058432de721.js
---- ink-falling_edgeActions-9bdaa1845a29b15bd2562058432de721.js.gz
---- inkAnimationTrigger-3c35d0b73061bb5de0e691d694925902.js
---- inkAnimationTrigger-3c35d0b73061bb5de0e691d694925902.js.gz
Why won't ink-falling_edge-....js precompile?
I'm using ruby "2.0.0" and gem 'rails', '4.0.0'
This comment worked:
Why not try this line: config.assets.precompile +=
['edge/ink-falling_edge.js'] -> Rails may only reference files by
their (non ERB) asset filename - Rich Peck
my team and i have been trying to figure this one out for weeks to no avail. Every time we precompile our assets on our production server, our application will begin to load all of our assets twice (once as a precompiled script, and then again as each asset individually). This problem usually occurs between 2-5 days after the precompile (in other words, it works for a few days before breaking). I'm really not certain why this is happening.
I have seen a lot of other people with the same issue, but their issues are always pertaining to the development environment. However, our application's environment is in production.
here is our method for precompiling:
rake assets:clean
rake assets:precompile
here is my /config/environment.rb:
# Load the rails application
require File.expand_path('../application', __FILE__)
ENV['RAILS_ENV'] ||= 'production'
# Initialize the rails application
Myapp::Application.initialize!
here is my /config/environments/production.rb:
Myapp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = false
# 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 = false
# Compress JavaScripts and CSS
config.assets.compress = true
# 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
# BEGIN ICONIC PRECOMPILE ISSUE FIX
# add iconic path to precompile
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
# Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf )
# END ICONIC PRECOMPILE ISSUE FIX
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = '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
# See everything in the log (default is :info)
config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# 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
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
end
and, although i don't see why you would need it, here is my /config/environments/development.rb:
Myapp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server 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.raise_delivery_errors = false
# 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
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
end
***UPDATE*
as per the suggested answer, I have modified my environments/production.rb. it now looks like this:
Myapp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = false
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true
# config.assets.debug = false
# Compress JavaScripts and CSS
config.assets.compress = true
# 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
# BEGIN ICONIC PRECOMPILE ISSUE FIX
# add iconic path to precompile
# config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
# Precompile additional assets
# config.assets.precompile += %w( .svg .eot .woff .ttf )
# END ICONIC PRECOMPILE ISSUE FIX
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = '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
# See everything in the log (default is :info)
config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# 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
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
end
instead of fixing my problem, all of my assets are now loading twice immediately after precompiling. I'm not sure what I'm doing wrong here.
here are the commands i'm running:
rm -rf public/assets
rake assets:clean
rake assets:precompile
any insight would be greatly appreciated. thanks!
Maybe disabling the live compilation of assets on production could fix your issue.
In your config/environments/production.rb set:
config.assets.compile = false
Take a quick look at this question. It may clarify the "after a few days" part of the issue.
GL & HF
You say that all of your assets are being loaded once from application.css / application.js and then again from their individual files. From what you said, it sounds like you have a bunch of <script> and <style> tags in your <head> element - is that true? That should only happen when you have config.assets.debug = true. In production, the individual files should not appear there at all. You should only have application.css and application.js.
This makes me think that something about your production configuration is wrong or that the wrong environment configuration is being used on your server.
(It could also happen if you added links to the individual files in your layout. Are you doing that?)
It would be easier to debug if you provided the <head> element of your document + the head section of your application layout (or whatever layout you're using).
A few thoughts:
Is your server setting RAILS_ENV=production?
When you compile your assets on your production machine, are you setting RAILS_ENV=production for the rake task?
Is your clock correct on your production machine?
Are your assets really being loaded twice, or are you just seeing JS callbacks fire multiple times? If you're using Turbolinks, any JS in the body of your document that attaches on-document-ready callbacks will begin firing multiple times once you have clicked on any turbolinks-enabled link (but not after a fresh load).
You still have "config.assets.compile = true" in your updated config. You shouldn't need that if you're precompiling assets, and it can cover up problems, so I would suggest changing it back to false.
Here is the assets config I'm using for production apps:
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# 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
Please try with that config and keep us updated.
I'm precompiling assets locally and pushing them to S3. In production I get this error:
heroku[router]: at=info method=GET path=/ host=www.someapp.org fwd="76.87.106.226" dyno=web.1 connect=2ms service=614ms status=500 bytes=0
app[web.1]: ActionView::Template::Error (couldn't find file 'bootstrap'
app[web.1]: app/views/application/_stylesheets.html.erb:1:in `...'
app[web.1]: app/views/layouts/application.html.erb:5:in `...'
app[web.1]:
app[web.1]: (in /app/app/assets/stylesheets/application.css:11)):
app[web.1]: 1: <%= stylesheet_link_tag "application", media: "all" %>
When I run in production mode locally I do not get that error.
Here is my application.rb:
require File.expand_path("../boot", __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
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 SomeApp
class Application < Rails::Application
require "ksp"
require "markdowner"
require "patches/carrier_wave"
VERSION = "1.0.0"
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = "Central Time (US & Canada)"
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join("my", "locales", "*.{rb,yml}").to_s]
# config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9.
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
# Use SQL instead of Active Record"s schema dumper when creating the database.
# This is necessary if your schema can"t be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
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"
config.generators do |generator|
generator.test_framework :rspec, view_specs: false
end
config.assets.prefix = "/assets/#{Rails.env}"
config.filepicker_rails.api_key = ENV["FILEPICKER_API_KEY"]
# Allow for CORS requests
config.middleware.use Rack::Cors do
allow do
origins "*"
resource "*", headers: :any, methods: [:get, :post, :options]
end
end
end
end
Here is my production.rb:
SomeApp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# 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 = false
# 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 nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
config.action_dispatch.x_sendfile_header = '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
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
config.cache_store = :dalli_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
config.action_controller.asset_host = "d20eprk8nbwd96.cloudfront.net"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { host: "www.someapp.org" }
# 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
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
end
Here is my asset_sync.rb:
if defined?(AssetSync) && !(ENV["HOME"] == "/app")
AssetSync.configure do |config|
config.fog_provider = "AWS"
config.fog_directory = ENV["AMAZON_BUCKET"]
config.aws_access_key_id = ENV["AMAZON_S3_KEY"]
config.aws_secret_access_key = ENV["AMAZON_S3_SECRET"]
# Increase upload performance by configuring your region
config.fog_region = "us-west-2"
#
# Don't delete files from the store
config.existing_remote_files = ENV["ASSET_SYNC_EXISTING_REMOTE_FILES"]
#
# Automatically replace files with their equivalent gzip compressed version
config.gzip_compression = ENV["ASSET_SYNC_GZIP_COMPRESSION"]
#
# Use the Rails generated 'manifest.yml' file to produce the list of files to
# upload instead of searching the assets directory.
config.manifest = ENV["ASSET_SYNC_MANIFEST"]
#
# Fail silently. Useful for environments such as Heroku
# config.fail_silently = true
end
end
Here is my application.css:
/*
*= require bootstrap
*= require bootstrap-responsive
*= require font-awesome
*= require chosen
*= require bootstrap/tour
*= require bootstrap/lightbox
*= require_self
*/
In production mode locally the method gives me the correct cloudfront URL.
What's going wrong here?
Turns out despite precompiling locally, Heroku was still trying to precompile on Heroku.
It would fail, and then try to compile the assets live. This would then fail in the way described.
I solved this by creating an empty file /public/assets/manifest.yml, even though my config says assets are in /public/assets/production/
When i run my application in development my datatables table is showing
but when i run my app in production datatables is not showing. only the records ar shown.
screenshot in developemnt:
screenshot in production:
My production.rb:
Contractbeheerpj::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# 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 = false
# Compress JavaScripts and CSS
config.assets.compress = true
# 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
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = '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
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# 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
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
end
Hope someone can help! :)
Your issue is probably because of Rails Asset pipelining which Rails in production precompiles your js files to public/assets hence your js file is either not loaded or is an older version. Look at this answer to a similar issue to what you are having.