Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to comment out rails 3.1 asset require statement

Is it possible to comment out this line in the new app/assets/application.js file? If so, how?

//=require jquery_ujs

I mean, it's already commented out to avoid being misconstrued as CoffeeScript or JavaScript, but it's obviously serving a purpose still.

like image 209
c3rin Avatar asked May 20 '11 17:05

c3rin


People also ask

How do you Precompile an asset?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

What does rake assets Precompile do?

RAILS_ENV=production tells Rails to compile the production version of the assets. assets:precompile is a Rails provided rake task that has instructions for compiling the assets.

What is manifest JS in Rails?

A manifest typically includes special comments, called directives, to add JavaScript files to a bundle. The contents of a typical Rails manifest looks something like this: your_app/app/assets/javascripts/application.


2 Answers

Taken from the Sprockets 1.02 github (Sprockets 2 is what rails 3.1 uses to accomplish asset loading):

How Sprockets handles comments

Use single-line (//) comments in JavaScript source files for comments that don't need to appear in the resulting concatenated output.Use multiple-line (/* ... */) comments for comments that should appear in the resulting concatenated output, like copyright notices or descriptive headers. PDoc (/** ... **/) documentation comments will not be included in the resulting concatenation.

Comments beginning with //= are treated by Sprockets as directives. Sprockets currently understands two directives, require and provide.

What this means is that //= jquery_ujs is a directive. It instructs Sprockets to include the jquery_uls file when it compiles all the jquery files.

If you don't want that file included, just remove the equals sign and the directive becomes a comment.

like image 131
David Tuite Avatar answered Oct 05 '22 03:10

David Tuite


Short and fast ...

//require jquery_ujs

... just remove the = sign.

like image 26
static RYU Avatar answered Oct 05 '22 03:10

static RYU