1

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?

1
  • the syntax error comes only if you have any curly bracket that either does not closed or added extra. if you have include more js file before this then check the sytax in those file. Commented Jun 30, 2012 at 18:29

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.