Reputation: 8189
I have a functioning JavaScript program and if I paste the code directly into a Rails view, it works fine. When I place it in assets/javascript and call it with a javascript_include_tag, I start getting syntax errors for every occurrence of a curly bracket. For instance:
var rect = {};
throws an error, while:
var rect = new Object();
does not. Similarly, creating an object like this throws an error:
function tag(x, y, width, height){
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.book = books[0];
}
Anyone know what's going on?
Upvotes: 1
Views: 138
Reputation: 23648
I can only guess but maybe you forgot to rename your javascript files that got generated for you?
As of Rails 3.1 it by default creates those files with the .coffee
extension so it expects Coffeescript to be written in them.
Simply try renaming them to .js
instead of .js.coffee
and it should work
Upvotes: 1