Вопрос

Application is rich on javascript, contains bunch of backbonejs classes, jquery, bootstrap, and many libraries.

Without precompile, everything works great. However, when I run rake assets:precompile locally or on production server, problem appear.

Uncaught TypeError: undefined is not a function                  application.js:8

application.js contains everything (just first glance), so I have no idea where can be a problem. Even I have no idea where to start looking for a problem. It's impossible to debug output javasript in application.js, right?

Any ideas? Thanks guys.

Это было полезно?

Решение 2

After hours of debugging, I found out where is a problem.

PostsRouter is name of router in the code, when it gets precompiled, name of class is changed to "n", which is bad because in constructor I have this code below

this.constructor.toString().match(/function\s*(\w+)/)

So I get wrong class name, but that's still OK. Then I'm doing this:

new App.Collections["" + this.class_name + "Collection"]

and that's the problem. App.Collections.nCollection not exists, correct name is App.Collections.PostsCollection.

I fix it by adding string literal into class definition, instead of parsing from constructor name.

Have a nice day!

Другие советы

You are probably concatenating files out of order. Make sure that you are loading all of your dependencies in the proper order. Eg: underscore must be loaded before backbone.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top