c3rin
c3rin

Reputation: 1917

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.

Upvotes: 20

Views: 5195

Answers (4)

Christopher Oezbek
Christopher Oezbek

Reputation: 26353

What I hate about this, is that it is really looking for a = inside a single line comment instead of the combination of //=.

To disable, put the // after the //=:

//= // require jquery_ujs

or kill the equal sign

// require jquery_ujs

Anything before the = will not work:

//!= require jquery_ujs

Upvotes: 5

David Tuite
David Tuite

Reputation: 22643

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.

Upvotes: 32

static RYU
static RYU

Reputation: 141

Short and fast ...

//require jquery_ujs

... just remove the = sign.

Upvotes: 14

Edison Machado
Edison Machado

Reputation: 1410

You can do something like this:

///* My Application Scripts
//= 'require jquery'
//= 'require jquery_ujs'
//= require_tree .
//= require_self
*///

require lines with ('') will not be loaded.

Upvotes: 1

Related Questions