Javascript not loading in Rails Test Environment - javascript

I can't get Javascript to load in the browser in the rails test environment. This is problematic for cucumber selenium tests through capybara. Here's my test.rb (the default as far as I know)
MyApp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
# 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
# Raise exceptions instead of rendering exception templates
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
end
This results in a concatinated application.js with everything. I've tried adding config.assets.debug = true so that the assets aren't concatinated, and then only sometimes the javascript is loaded. If I copy over development.rb it seems to work, but that doesn't seem ideal.
Thanks!

Turns out it was the less-rails-bootstrap version 3.0.1 gem was loading twitter/bootstrap in the wrong order due to inter-dependencies. We never noticed this is in development because Rails does not compress assets in the development environment, by default. So those particular files weren't being loaded, but they didn't keep all of our javascript from loading like they were in test.
Upgrading to less-rails-bootstrap 3.0.3, or requiring individual components of twitter/bootstrap in the correct order in application.js solved the problem.

Related

Error during SonarQube Scanner exection

I'm pretty new to analysing Code with SonarQube. Since i installed it, I ran twice in the "Java.OutOfMemoryError"-error. I tried a few Things, suggested by others on this site.
My configuration in SonarQube:
# WEB SERVER
# Web server is executed in a dedicated Java process. By default heap size is 512Mb.
# Use the following property to customize JVM options.
# Recommendations:
#
# The HotSpot Server VM is recommended. The property -server should be added if server mode
# is not enabled by default on your environment:
# http://docs.oracle.com/javase/8/docs/technotes/guides/vm/server-class.html
#
sonar.web.javaOpts=-Xmx4G -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Djava.net.preferIPv4Stack=true -server
# Same as previous property, but allows to not repeat all other settings like -Xmx
#sonar.web.javaAdditionalOpts=
# Binding IP address. For servers with more than one IP address, this property specifies which
# address will be used for listening on the specified ports.
# By default, ports will be used on all IP addresses associated with the server.
#sonar.web.host=0.0.0.0
# Web context. When set, it must start with forward slash (for example /sonarqube).
# The default value is root context (empty value).
#sonar.web.context=
# TCP port for incoming HTTP connections. Default value is 9000.
#sonar.web.port=9000
# The maximum number of connections that the server will accept and process at any given time.
# When this number has been reached, the server will not accept any more connections until
# the number of connections falls below this value. The operating system may still accept connections
# based on the sonar.web.connections.acceptCount property. The default value is 50.
#sonar.web.http.maxThreads=50
# The minimum number of threads always kept running. The default value is 5.
#sonar.web.http.minThreads=5
# The maximum queue length for incoming connection requests when all possible request processing
# threads are in use. Any requests received when the queue is full will be refused.
# The default value is 25.
#sonar.web.http.acceptCount=25
# TCP port for incoming AJP connections. Disabled if value is -1. Disabled by default.
#sonar.ajp.port=-1
#--------------------------------------------------------------------------------------------------
# COMPUTE ENGINE
# The Compute Engine is responsible for processing background tasks.
# Compute Engine is executed in a dedicated Java process. Default heap size is 512Mb.
# Use the following property to customize JVM options.
# Recommendations:
#
# The HotSpot Server VM is recommended. The property -server should be added if server mode
# is not enabled by default on your environment:
# http://docs.oracle.com/javase/8/docs/technotes/guides/vm/server-class.html
#
sonar.ce.javaOpts=-Xmx16G -Xms128m -XX:+HeapDumpOnOutOfMemoryError -XX:-UseGCOverheadLimit -Djava.net.preferIPv4Stack=true -server
# Same as previous property, but allows to not repeat all other settings like -Xmx
#sonar.ce.javaAdditionalOpts=
# The number of workers in the Compute Engine. Value must be greater than zero.
# By default the Compute Engine uses a single worker and therefore processes tasks one at a time.
# Recommendations:
#
# Using N workers will require N times as much Heap memory (see property
# sonar.ce.javaOpts to tune heap) and produce N times as much IOs on disk, database and
# Elasticsearch. The number of workers must suit your environment.
#sonar.ce.workerCount=1
#--------------------------------------------------------------------------------------------------
# ELASTICSEARCH
# Elasticsearch is used to facilitate fast and accurate information retrieval.
# It is executed in a dedicated Java process. Default heap size is 1Gb.
# JVM options of Elasticsearch process
# Recommendations:
#
# Use HotSpot Server VM. The property -server should be added if server mode
# is not enabled by default on your environment:
# http://docs.oracle.com/javase/8/docs/technotes/guides/vm/server-class.html
#
sonar.search.javaOpts=-Xmx2G -Xms256m -Xss256k -Djava.net.preferIPv4Stack=true \
-XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 \
-XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:-UseGCOverheadLimit
# Same as previous property, but allows to not repeat all other settings like -Xmx
#sonar.search.javaAdditionalOpts=
# Elasticsearch port. Default is 9001. Use 0 to get a free port.
# As a security precaution, should be blocked by a firewall and not exposed to the Internet.
#sonar.search.port=9001
# Elasticsearch host. The search server will bind this address and the search client will connect to it.
# Default is 127.0.0.1.
# As a security precaution, should NOT be set to a publicly available address.
#sonar.search.host=127.0.0.1
#--------------------------------------------------------------------------------------------------
The error message:
ERROR: Error during SonarQube Scanner execution
INFO: Final Memory: 41M/910M
INFO: ------------------------------------------------------------------------
java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.grow(Unknown Source)
at java.util.ArrayList.ensureExplicitCapacity(Unknown Source)
at java.util.ArrayList.ensureCapacityInternal(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.convertChildren(SyntaxTreeCreator.java:143)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:119)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:72)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:89)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:72)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.convertChildren(SyntaxTreeCreator.java:129)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:119)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:72)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:89)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:72)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.convertChildren(SyntaxTreeCreator.java:129)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:119)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:72)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:89)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:72)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.convertChildren(SyntaxTreeCreator.java:129)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:119)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:72)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:89)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:72)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.convertChildren(SyntaxTreeCreator.java:129)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:119)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:72)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:89)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:72)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.convertChildren(SyntaxTreeCreator.java:129)
at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:119)
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
System.Exception: Unexpected exit code received from batch file: 1
at Microsoft.TeamFoundation.DistributedTask.Task.Internal.PowerShell.InvokeBatchScriptCmdlet.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
Things I already tried:
Give SonarQube more Memory - As you might see in my configuration I changed the variable "sonar.web.javaOpts", "sonar.ce.javaOpts" and "sonar.search.javaOpts"
SonarQube ran into an error while analysing a ~1MB array. Since it were only test-data, I deleted the file and tried to run the analyse again. And yay! At least a different error....
ERROR: Error during SonarQube Scanner execution
org.sonar.squidbridge.api.AnalysisException: Unable to analyse file: C:/B/B01/15/s/src/org.scn.community.geovis/script/node_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/compress.js
at org.sonar.plugins.javascript.JavaScriptSquidSensor.analyse(JavaScriptSquidSensor.java:195)
at org.sonar.plugins.javascript.JavaScriptSquidSensor.analyseFiles(JavaScriptSquidSensor.java:161)
at org.sonar.plugins.javascript.JavaScriptSquidSensor.analyse(JavaScriptSquidSensor.java:152)
at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:58)
at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:50)
at org.sonar.batch.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:83)
at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:192)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:241)
at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:236)
at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:226)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
at org.sonar.batch.task.ScanTask.execute(ScanTask.java:47)
at org.sonar.batch.task.TaskContainer.doAfterStart(TaskContainer.java:86)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:106)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:119)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)
at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalStateException: No break target can be found for label out
at com.google.common.base.Preconditions.checkState(Preconditions.java:145)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.visitBreakStatement(ControlFlowGraphBuilder.java:446)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.build(ControlFlowGraphBuilder.java:223)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.buildSubFlow(ControlFlowGraphBuilder.java:641)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.visitIfStatement(ControlFlowGraphBuilder.java:458)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.build(ControlFlowGraphBuilder.java:211)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.build(ControlFlowGraphBuilder.java:199)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.visitBlock(ControlFlowGraphBuilder.java:393)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.build(ControlFlowGraphBuilder.java:227)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.visitTryStatement(ControlFlowGraphBuilder.java:575)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.build(ControlFlowGraphBuilder.java:231)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.buildSubFlow(ControlFlowGraphBuilder.java:641)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.visitIfStatement(ControlFlowGraphBuilder.java:458)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.build(ControlFlowGraphBuilder.java:211)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.visitLabelledStatement(ControlFlowGraphBuilder.java:535)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.build(ControlFlowGraphBuilder.java:229)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.build(ControlFlowGraphBuilder.java:199)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.createGraph(ControlFlowGraphBuilder.java:161)
at org.sonar.javascript.cfg.ControlFlowGraphBuilder.createGraph(ControlFlowGraphBuilder.java:156)
at org.sonar.javascript.cfg.ControlFlowGraph.build(ControlFlowGraph.java:107)
at org.sonar.javascript.checks.DeadStoreCheck.checkFunction(DeadStoreCheck.java:98)
at org.sonar.javascript.checks.DeadStoreCheck.visitFunctionExpression(DeadStoreCheck.java:77)
at org.sonar.javascript.tree.impl.expression.FunctionExpressionTreeImpl.accept(FunctionExpressionTreeImpl.java:174)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:114)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:125)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.visitParameterList(DoubleDispatchVisitor.java:222)
at org.sonar.javascript.tree.impl.declaration.ParameterListTreeImpl.accept(ParameterListTreeImpl.java:98)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:114)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.visitCallExpression(DoubleDispatchVisitor.java:438)
at org.sonar.javascript.tree.impl.expression.CallExpressionTreeImpl.accept(CallExpressionTreeImpl.java:68)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:114)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.visitExpressionStatement(DoubleDispatchVisitor.java:250)
at org.sonar.javascript.tree.impl.statement.ExpressionStatementTreeImpl.accept(ExpressionStatementTreeImpl.java:66)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:114)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:125)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.visitBlock(DoubleDispatchVisitor.java:234)
at org.sonar.javascript.tree.impl.statement.BlockTreeImpl.accept(BlockTreeImpl.java:83)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:114)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.visitFunctionExpression(DoubleDispatchVisitor.java:483)
at org.sonar.javascript.checks.DeadStoreCheck.visitFunctionExpression(DeadStoreCheck.java:78)
at org.sonar.javascript.tree.impl.expression.FunctionExpressionTreeImpl.accept(FunctionExpressionTreeImpl.java:174)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:114)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.visitParenthesisedExpression(DoubleDispatchVisitor.java:459)
at org.sonar.javascript.tree.impl.expression.ParenthesisedExpressionTreeImpl.accept(ParenthesisedExpressionTreeImpl.java:80)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:114)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.visitCallExpression(DoubleDispatchVisitor.java:437)
at org.sonar.javascript.tree.impl.expression.CallExpressionTreeImpl.accept(CallExpressionTreeImpl.java:68)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:114)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.visitExpressionStatement(DoubleDispatchVisitor.java:250)
at org.sonar.javascript.tree.impl.statement.ExpressionStatementTreeImpl.accept(ExpressionStatementTreeImpl.java:66)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:114)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:125)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.visitModule(DoubleDispatchVisitor.java:146)
at org.sonar.javascript.tree.impl.declaration.ModuleTreeImpl.accept(ModuleTreeImpl.java:56)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:114)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.visitScript(DoubleDispatchVisitor.java:141)
at org.sonar.javascript.tree.impl.declaration.ScriptTreeImpl.accept(ScriptTreeImpl.java:73)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scan(DoubleDispatchVisitor.java:114)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitor.scanTree(DoubleDispatchVisitor.java:109)
at org.sonar.plugins.javascript.api.visitors.DoubleDispatchVisitorCheck.scanFile(DoubleDispatchVisitorCheck.java:34)
at org.sonar.plugins.javascript.JavaScriptSquidSensor.scanFile(JavaScriptSquidSensor.java:232)
at org.sonar.plugins.javascript.JavaScriptSquidSensor.analyse(JavaScriptSquidSensor.java:185)
... 31 more
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
System.Exception: Unexpected exit code received from batch file: 1
at Microsoft.TeamFoundation.DistributedTask.Task.Internal.PowerShell.InvokeBatchScriptCmdlet.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
The Code I tried to Analyse: https://github.com/org-scn-design-studio-community/sdkpackage
So yeah, here I am, confused and without ideas how to proceed. Is anyone out there able to help me?
If you can't exclude dependencies I suggest you go to your SonarQube's update center ( Administration/System/Update Center ) and install the latest version of SonarJS. I've tested that your issue does not appear in SonarJS 3.0 and above.
In general though, it's not a good idea to analyze dependencies. If your company wants to address security concerns on dependencies it's probably better to analyze the dependencies on their own, not as part of a larger project.
The analysis fails on the following file:
C:/B/B01/15/s/src/org.scn.community.geovis/script/node_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/compress.js
This is a dependency of your project and you shouldn't analyse it: you should only analyse the code of your project. Add the following line to your sonar-project.properties:
sonar.exclusions=**/node_modules/**/*

Rails 3.2 continues to serve OLD version of JavaScript asset file - Development Env

I have a Rails 3.2 application, and in it I have a Javascript file (app.'s) which appears to be 'stuck' at a particular, past, version. I've updated the file many times, changing its contents significantly, and being sure each time to Save the file - to no effect. I've rebooted the machine multiple times (thinking at least THAT should clear out the cobwebs) all to no avail. I'm at my wits end trying to think of ways to un-stick this.
I can see that the file is being served, each time I visit the page:
Started GET "/dev-assets/app.js?body=1" for 172.16.0.12 at 2014-04-24 16:49:36 -0700
Served asset /app.js - 200 OK (1ms)
And then later in the same test run (not modified - as I expect):
Started GET "/dev-assets/app.js?body=1" for 172.16.0.10 at 2014-04-24 16:51:31 -0700
Served asset /app.js - 304 Not Modified (0ms)
But STILL it has the old contents (which, have a call to 'location.assign' which has since been removed - so the behavior should be significantly different than what I'm seeing.
I have these settings in my development.rb file (but this is not the complete file):
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
# From Rails issue 10091 - attemp to keep from loading scripts
# multiple times
config.assets.prefix = "/dev-assets"
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
# Workaround documented in Rails issue 4145
config.serve_static_assets = false
Anyone have any idea how I can clear this old file?
Note - this is very similar to:
Clear the cache from the Rails asset pipeline
But none of those suggestions have helped me.
This isn't a Rails problem. Rails is serving up the correct file, as verified by by fetching the file in the browser:
http://localhost:3000/dev-assets/app.js

Rails custom layouts - routingerror in production

I have an admin section of my site that uses an 'admin' layout.
class Admin::BaseController < ActionController::Base
layout "admin"
in layouts/admin.html.slim
= stylesheet_link_tag "admin", :media => "all"
= javascript_include_tag "admin"
I get an error for the admin.js and admin.css
Started GET "/stylesheets/admin.css" for x.x.x.x at 2013-10-25 13:18:16 +0000
F, [2013-10-25T13:18:16.505425 #31550] FATAL -- :
ActionController::RoutingError (No route matches [GET] "/stylesheets/admin.css"):
this works perfectly in development and the frontend assets are loading normally in production, what can the problem be?
The reason is that your rails server (webrick, thin, ...) serves your assets uncompiled, where it looks for it in several places (like app/assets or vendor/assets). In production, rails assumes that the production webserver handles asset serving, which are served from public/.
Since compilation on runtime – or delivering them uncompiled at all – slows down page serving, they are compiled into the name of its known manifest-files that reference your styles (that is application.{css/js} by default), which you do by invoking rake assets:precompile.
Add config.assets.precompile += %w( admin.css ) to config/application.rb or config/environments/production.rb to add your admin.css manifest so rails know that it also has to compile that one. Then run rake assets:precompile (if you've put it into the later, you may need to add RAILS_ENV=production).

Jquery not working after precompile

An image was causing a problem on my heroku app so I changed config.assets.compile = false to config.assets.compile = true in production.rb. I then ran rake assets:precompile and pushed to the heroku server. Jquery works fine on the app website, but no longer works on my local copy. No errors are thrown in the javascript console. Here are some important files as they stand now.
Production.rb
Nonogrammed::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 = :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
Application.js
//= require jquery
//= require jquery_ujs
//= require jquery.ui.core
//= require jquery.ui.widget
//= require jquery.ui.mouse
//= require jquery.ui.draggable
//= require twitter/bootstrap
//= require_tree .
$(function() {
$( "#draggable" ).draggable({ handle: "#handle" , containment: [0,0,1200,1000] , cursor: "crosshair" });
});
UPDATE: This was caused by deleting an image , making a new image with the same name, and then pushing to heroku. Don't do that!
There's no need to precompile on your local. Sprockets automatically compiles static asset at server start.
To resolve things, delete the compiled files in the public/assets directory, commit your changes, then deploy to Heroku again.
Then, in Heroku, compile your assets by running the following from your command line:
# from command line via the Heroku Toolbelt
rake run assets:precompile
Your local assets will compile on server start (thus rendering jQuery usable again), and your assets on Heroku will be precompiled to the public/assets directory as they should be.
UPDATE:
You may need to clear your browser cache to ensure that the updated asset path is loaded into your markup.

Rails Heroku Precompiled Assets Not Loading JS?

I'm setting up my Rails app on Heroku, and running into a problem where all my CSS assets are loaded but none of my JS assets are. I'm using memcached, and followed these instructions: https://devcenter.heroku.com/articles/rack-cache-memcached-rails31.
One thing I noticed is that when I change config.assets.compile to "true" in my production.rb file, all the JS is loaded successfully but obviously the initial load of the site is tremendously slow. How can I troubleshoot this problem? I'm new to Heroku, so am unsure and haven't found anything online that is helpful.
I assume that since all my JS files are in /assets/javascripts/, that the should be included automatically, but it seems as if they're not.
Here's my production.rb:
BrainDb::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
client = Dalli::Client.new
config.action_dispatch.rack_cache = {
:metastore => client,
:entitystore => client,
:allow_reload => false
}
# 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
config.static_cache_control = "public, max-age=2592000"
# 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
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
end
I also removed everything from public/assets so it would precompile. Here's 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 BrainDb
class Application < Rails::Application
# 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
config.active_record.whitelist_attributes = true
config.assets.initialize_on_precompile = false
# Enable the asset pipeline
config.assets.enabled = true
config.cache_store = :dalli_store
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end
end
UPDATE
Application.js:
//
//= require jquery
//= require jquery_ujs
Add
//= require_tree . at last and precompile
in your application.js.

Categories