Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming application.js to application.js.coffee?

Starting a new project, I just try to rename my application.js to application.js.coffee.

Rails raise a error : SyntaxError: unexpected IDENTIFIER (in my_path/application.js.coffee)

Application.js is empty, just jquery include :

//= require jquery
//= require jquery_ujs

Any ideas? Thanks

like image 411
Yoann Augen Avatar asked Aug 13 '13 16:08

Yoann Augen


2 Answers

Why would you want to do that?

It is not recommended to add code to your application.js.

If you need to run a coffee script just create a coffee file in the same folder and it will include it automatically.

From the comments in the file:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//

This file is not your regular .js file, it serves the purpose of serving your javascripts to the asset pipeline, its not a good practice to add code here.

Whatever you need to do it can be done another way...

like image 52
Rodrigo Zurek Avatar answered Nov 06 '22 04:11

Rodrigo Zurek


Comments in coffeescript are written with # so replace with:

#= require jquery
#= require jquery_ujs
like image 33
apneadiving Avatar answered Nov 06 '22 05:11

apneadiving