dnagir / knockout-rails

KnockoutJS for Rails with Sweetness
96 stars 16 forks source link

Trying example #3

Closed amalagaura closed 13 years ago

amalagaura commented 13 years ago

I try the example as follows:

class User extends ko.Model
    @configure 'user' # This is enough to save the model RESTfully to `/users/{id}` URL

And I get this generated javascript

(function() {
  var User;
  var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
  User = (function() {
    __extends(User, ko.Model);
    function User() {
      User.__super__.constructor.apply(this, arguments);
    }
    User.configure('user');
    return User;
  })();
}).call(this);

And I get the error that ko is not defined: , but knockout.js is loaded with it's dependencies. And when I do a ko or ko.model from the console, it is defined. is it because this is not waiting for all javascript resources to load before executing? It's tough to show, so here is a screenshot.

http://i.imgur.com/99McT.png

Here is contents of application.js

//
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require knockout
amalagaura commented 13 years ago

Sorry for the bad formatting, dunno what is with this damn markdown

dnagir commented 13 years ago

You must require knockout before requiring any of your code (require_tree ..)

So change your application.js to:

//= require jquery
//= require jquery_ujs
//= require knockout
//= require_tree .