title: Rails asset pipeline + knockout.js
body: <p>I'm trying to implement knockout.js in Rails 3.2.6. I'm using the Gem <a href="https://github.com/jswanner/knockoutjs-rails" rel="nofollow">https://github.com/jswanner/knockoutjs-rails</a>. </p>
  
  <p>I'm having trouble loading the ViewModel.</p>
  
  <p>Here's my HTML for debugging</p>
  
  <pre><code>&lt;div data-bind="text: ko.toJSON(users)"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Here's the JavaScript compiled from CoffeeScript. The file is <code>users.js.coffee</code> and is included in the asset pipeline via <code>//= require_tree .</code> in <code>application.js</code></p>
  
  <pre><code>(function() {
  
    jQuery(function() {
      var User, UserViewModel;    
      User = function(id, name) {
        var self;
        self = this;
        self.id = ko.observable(id);
        self.name = ko.observable(name);
        return self.followers_count_message = ko.computed(function() {});
      };
      UserViewModel = function() {
        var self;
        self = this;
        self.users = ko.observableArray([new User('1111', 'test name'), new User('1112', 'test name2')]);
        self.addUsers = function() {
          return self.users.push(new User('1113', 'test name'));
        };
        return self.addUsers();
      };
      ko.applyBindings(new UserViewModel());
      return alert('done');
    });
  
  }).call(this);
  </code></pre>
  
  <p>Upon loading, the div displays this: <code>[null,null,null]</code></p>
  
  <p>The odd thing is if I implement this in jsFiddle, it seems to work. See this: <a href="http://jsfiddle.net/netwire88/HXYHU/2/" rel="nofollow">http://jsfiddle.net/netwire88/HXYHU/2/</a></p>
  
  <p>Thoughts, ideas?</p>
  
  <p><strong>UPDATE: 7/31/2012</strong></p>
  
  <p>I was able to fix this by changing the functions to remove the <code>return</code>. However, I would like to move it to another CoffeeScript file. </p>
  
  <p>I tried this in <code>users.js.coffee</code>, however, I'm getting error <code>Uncaught TypeError: Cannot read property 'nodeType' of null</code></p>
  
  <pre><code>User = (id, name) -&gt;
    self = undefined
    self = this
    self.id = ko.observable(id)
    self.name = ko.observable(name)
    @
  
  UserViewModel = -&gt;
    self = this
    self.users = ko.observableArray([new User("1111", "test name"), new User("1112", "test name2")])
    self.addUsers = -&gt;
      self.users.push new User("1113", "test name")
    self.addUsers()
    @
  
  ko.applyBindings new UserViewModel()
  </code></pre>