Uncaught TypeError: undefined is not a function rails3/backbone/js

后端 未结 5 1252
臣服心动
臣服心动 2021-02-14 08:38

I just started delving into javascript to make project more responsive and I am working through a backbone.js example.

I\'ve replicated http://www.jamesyu.org/2011/01/27

相关标签:
5条回答
  • 2021-02-14 09:28

    It sounds like you are not including the file that holds the declaration of App.Controllers.Fffforms. Make sure that you are including that file somewhere in you code prior to where you include application.js.

    0 讨论(0)
  • 2021-02-14 09:29

    I presume there is a kind of bundling mechanism there in your app. Make sure all files have correct usage of semicolons (;) in all bundled files.

    0 讨论(0)
  • 2021-02-14 09:29

    This just bit me so I thought I'd share my find: make sure your file's line endings match your server's file system.

    0 讨论(0)
  • 2021-02-14 09:38

    My answer is similar to @ream88's, but Rails 3.1+ Asset Pipeline feature takes care of minification, bundling and so on, so I prefer to have the un-minified versions available for debugging, etc.

    So download the commented/full version of backbone.js and underscore.js and save them in app/assets/javascripts (you could also save them in vendor/assets/javascripts).

    The difference is that you should update the manifest file (app/assets/javascripts/application.js) to add the require directives, like so

    //= require jquery
    //= require jquery_ujs
    //= require underscore
    //= require backbone
    //= require_tree .
    

    Because backbone depends on underscore, this will cause them to get loaded in the right order, thus avoiding the error.

    0 讨论(0)
  • 2021-02-14 09:42

    Ran into the same problem, and then I figured out that I haven't included underscore.js anywhere. So I wrote a simple backbone.js file:

    /*
     *= require backbone/underscore-min.js
     *= require backbone/backbone-min.js
     */
    

    and stored it under vendor/assets/javascripts along with the Backbone and Underscore files:

    vendor/assets/javascripts/
    ├── backbone
    │   ├── backbone-min.js
    │   └── underscore-min.js
    └── backbone.js
    

    My application.js.coffee looks something like this one now:

    #= require backbone
    #= require query
    
    0 讨论(0)
提交回复
热议问题