title: class methods in Backbone
body: <p>I'm trying to implement authentication with Devise (an authentication gem for Rails) using Backbone. Users can sign out of Backbone by sending the DELETE request to <code>/users/sign_out/</code> so I couldn't get this link to work because if I click it it's a GET request</p>
  
  <pre><code>&lt;li&gt;&lt;a href="/users/sign_out" class="thumbnail plain"&gt;sign out&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>I then created a logout method on the User model, but to trigger it I have to have an instance of the user model (obviously). I created a logout method in the router that gets triggered by navigating to the <code>logout</code> route, but since I can only call <code>logout</code> on the user model with an instance of it, I'm creating a new model in the logout method just to call logout. </p>
  
  <pre><code>    "logout": "logout"
  
      },
  
      logout: function(){
       var foo = new app.Models.User
       foo.logout();
  
      }
  </code></pre>
  
  <p>This is obviously a bad idea but I don't know what else to do.  Can you recommend what I should be doing instead? Is there a way to make the logout a class method so I don't have to instantiate a new model just to logout or something else?</p>
  
  <p>Update</p>
  
  <p>This is the createUser method in the User model that sends the registration data to devise. In the success callback, it assigns the session to a variable <code>window.app.current_user = userSession;</code>. I also have a logout method on the user model that I try to call from the router like this </p>
  
  <p>logout in router</p>
  
  <pre><code>logout: function(){  
      window.app.current_user.logout();
      }
  </code></pre>
  
  <p>--</p>
  
  <pre><code>app.Models.User = Backbone.Model.extend({
        initialize:function () {       
  
      }, 
      createUser: function() {
      var user = {};
      user['email'] = this.get("email");
      user['password'] = this.get("password");
      user['password_confirmation'] = this.get("password_confirmation");
      var registration = {};
      registration['user'] = user; 
    var _this = this;
    $.ajax({
      url: '/users.json',
      type: "POST",
      data: {user: user, registration: registration},
      success: function(userSession, response) {
  
        window.app.current_user = userSession;
  
      },
  
     ... code ommitted
  
  logout: function(){
    var me;
    console.log("Logging out...");
    me = this;
    return $.ajax({
      url: '/users/sign_out',
      type: "DELETE",
      dataType: "json",
      success: function(data, textStatus, jqXHR) {
         window.app.current_user = '';
  
      },
      error: function(jqXHR, textStatus, errorThrown) {
        return alert("Error logging out: " + errorThrown);
      }
    });
  
  }, 
  </code></pre>