title: 401 unauthorized when trying to save Backbone model to rails db
body: <p>I am trying to match a song (in BBone world) through Rails to the DB.  I continually am getting a <code>POST http://localhost:3000/songs 401 (Unauthorized)</code> when trying to save in the BBone View.   The rails console error is below.  It appears that the parameter sent to Rails is duplicated in fields (data removed is below the Rails error, so to see to nesting), but would this prevent the data from getting saved, rather would it produce this error, as opposed to something more along the lines of 'too many fields'.</p>
  
  <p>As far as being unauthorized, that doesn't make sense, since the user ID is getting populated.
  Any thoughts?</p>
  
  <p>using <code>gem 'rails-backbone'</code></p>
  
  <p>Backbone Model:</p>
  
  <pre><code>//filename: song.js
  define([
    'underscore',
    'backbone',
    'backbone/collections/components'
  ], function(_, Backbone, componentCollection) {
    var songModel = Backbone.Model.extend({
      paramRoot: 'song',
      defaults: {
        title: '',
        content: '',
        user: '',
        components: componentCollection
      },
      initialize: function(){
      }
    });
  
    return songModel;
  });
  </code></pre>
  
  <p>Backbone View:</p>
  
  <pre><code>// Filename: views/songs/new_view
  define([
    'jquery',
    'underscore',
    'backbone',
    // Pull in the Collection module from above
    'backbone/collections/songsCollection',
    // 'backbone/views/songs/a_song_view',
    'text!backbone/templates/songs/new.html',
    'app/dispatch',
    'app/state'
  ], function($, _, Backbone, SongsCollection, songsTemplate, dispatch, state){
    return Backbone.View.extend({
  el: $('#songs'),
  
  initialize: function(options){
    //......
  },
  
  save: function(e){
    e.preventDefault();
    e.stopPropagation();
    var JSONSong = JSON.stringify(this.model.toJSON());
    this.model.unset("errors");
    this.model.set({
      title: $('#title').val(),
      content: JSONSong,
      user: $('#user').val()
    });
    return this.collection.create(this.model.toJSON(), {
      success: function(song) {
        console.log('saved!');
        this.model = song;
        return window.location.hash = "/" + this.model.id;
      },
      error: function(song, jqXHR) {
        return this.model.set({
          errors: $.parseJSON(jqXHR.responseText)
        });
      }
    });
  },
  
  render: function(){
    $(this.el).html('');
    var compiledTemplate = _.template ( songsTemplate, this.model.toJSON());
    $(this.el).html(compiledTemplate);
    return this;
  },
  });
  });
  </code></pre>
  
  <p>Rails Schema:</p>
  
  <pre><code>ActiveRecord::Schema.define(:version =&gt; 20130222200403) do
  
  
    create_table "songs", :force =&gt; true do |t|
      t.string   "title"
      t.string   "content"
      t.datetime "created_at", :null =&gt; false
      t.datetime "updated_at", :null =&gt; false
      t.integer  "user_id"
    end
  
    create_table "users", :force =&gt; true do |t|
      t.string   "email",                  :default =&gt; "", :null =&gt; false
      t.string   "encrypted_password",     :default =&gt; "", :null =&gt; false
      t.string   "reset_password_token"
      t.datetime "reset_password_sent_at"
      t.datetime "remember_created_at"
      t.integer  "sign_in_count",          :default =&gt; 0
      t.datetime "current_sign_in_at"
      t.datetime "last_sign_in_at"
      t.string   "current_sign_in_ip"
      t.string   "last_sign_in_ip"
    end
  
    add_index "users", ["email"], :name =&gt; "index_users_on_email", :unique =&gt; true
    add_index "users", ["reset_password_token"], :name =&gt; "index_users_on_reset_password_token", :unique =&gt; true
  
  end
  </code></pre>
  
  <p>Rails Console error:</p>
  
  <pre><code>Started POST "/songs" for 127.0.0.1 at 2013-02-25 16:45:56 -0500
  Processing by SongsController#create as JSON
    Parameters: {"title"=&gt;"1234", "content"=&gt;"{\"title\":\"1234\",\"content\":\"{\\\"title\\\":\\\"\\\",\\\"content\\\":\\\"\\\",\\\"user\\\":\\\"\\\",\\\"components\\\":[{\\\"label\\\":\\\"Snare\\\",\\\"img\\\":\\\"snare.png\\\",\\\"mute\\\":false,\\\"sample\\\":\\\"808_sd.m4a\\\",\\\"measures\\\":[{\\\"label\\\":\\\"0/4\\\",\\\"beats\\\":[{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false}],\\\"numberOfBeats\\\":0,\\\"divisions\\\":8}],\\\"active\\\":true,\\\"signature\\\":4,\\\"representation\\\":\\\"fraction\\\"},{\\\"label\\\":\\\"Hi Hat\\\",\\\"img\\\":\\\"hihat.png\\\",\\\"mute\\\":true,\\\"sample\\\":\\\"808_chh.m4a\\\",\\\"measures\\\":[{\\\"label\\\":\\\"0/4\\\",\\\"beats\\\":[{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false}],\\\"numberOfBeats\\\":0,\\\"divisions\\\":8}],\\\"active\\\":true,\\\"signature\\\":4,\\\"representation\\\":\\\"fraction\\\"},{\\\"label\\\":\\\"Kick Drum\\\",\\\"img\\\":\\\"kick.png\\\",\\\"mute\\\":true,\\\"sample\\\":\\\"808_bd.m4a\\\",\\\"measures\\\":[{\\\"label\\\":\\\"0/4\\\",\\\"beats\\\":[{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false}],\\\"numberOfBeats\\\":0,\\\"divisions\\\":8}],\\\"active\\\":false,\\\"signature\\\":4,\\\"representation\\\":\\\"fraction\\\"},{\\\"label\\\":\\\"Synth\\\",\\\"img\\\":\\\"synth.png\\\",\\\"mute\\\":true,\\\"sample\\\":\\\"ambass.mp3\\\",\\\"measures\\\":[{\\\"label\\\":\\\"0/4\\\",\\\"beats\\\":[{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false}],\\\"numberOfBeats\\\":0,\\\"divisions\\\":8}],\\\"active\\\":true,\\\"signature\\\":4,\\\"representation\\\":\\\"fraction\\\"}]}\",\"user\":\"1\",\"components\":[{\"label\":\"Snare\",\"img\":\"snare.png\",\"mute\":false,\"sample\":\"808_sd.m4a\",\"measures\":[{\"label\":\"0/4\",\"beats\":[{\"selected\":false},{\"selected\":false},{\"selected\":false},{\"selected\":false}],\"numberOfBeats\":0,\"divisions\":8}],\"active\":true,\"signature\":4,\"representation\":\"fraction\"},{\"label\":\"Hi Hat\",\"img\":\"hihat.png\",\"mute\":true,\"sample\":\"808_chh.m4a\",\"measures\":[{\"label\":\"0/4\",\"beats\":[{\"selected\":false},{\"selected\":false},{\"selected\":false},{\"selected\":false}],\"numberOfBeats\":0,\"divisions\":8}],\"active\":true,\"signature\":4,\"representation\":\"fraction\"},{\"label\":\"Kick Drum\",\"img\":\"kick.png\",\"mute\":true,\"sample\":\"808_bd.m4a\",\"measures\":[{\"label\":\"0/4\",\"beats\":[{\"selected\":false},{\"selected\":false},{\"selected\":false},{\"selected\":false}],\"numberOfBeats\":0,\"divisions\":8}],\"active\":false,\"signature\":4,\"representation\":\"fraction\"},{\"label\":\"Synth\",\"img\":\"synth.png\",\"mute\":true,\"sample\":\"ambass.mp3\",\"measures\":[{\"label\":\"0/4\",\"beats\":[{\"selected\":false},{\"selected\":false},{\"selected\":false},{\"selected\":false}],\"numberOfBeats\":0,\"divisions\":8}],\"active\":true,\"signature\":4,\"representation\":\"fraction\"}]}", "user"=&gt;"1", "components"=&gt;[{"label"=&gt;"Snare", "img"=&gt;"snare.png", "mute"=&gt;false, "sample"=&gt;"808_sd.m4a", "measures"=&gt;[{"label"=&gt;"0/4", "beats"=&gt;[{"selected"=&gt;false}, {"selected"=&gt;false}, {"selected"=&gt;false}, {"selected"=&gt;false}], "numberOfBeats"=&gt;0, "divisions"=&gt;8}], "active"=&gt;true, "signature"=&gt;4, "representation"=&gt;"fraction"}, {"label"=&gt;"Hi Hat", "img"=&gt;"hihat.png", "mute"=&gt;true, "sample"=&gt;"808_chh.m4a", "measures"=&gt;[{"label"=&gt;"0/4", "beats"=&gt;[{"selected"=&gt;false}, {"selected"=&gt;false}, {"selected"=&gt;false}, {"selected"=&gt;false}], "numberOfBeats"=&gt;0, "divisions"=&gt;8}], "active"=&gt;true, "signature"=&gt;4, "representation"=&gt;"fraction"}, {"label"=&gt;"Kick Drum", "img"=&gt;"kick.png", "mute"=&gt;true, "sample"=&gt;"808_bd.m4a", "measures"=&gt;[{"label"=&gt;"0/4", "beats"=&gt;[{"selected"=&gt;false}, {"selected"=&gt;false}, {"selected"=&gt;false}, {"selected"=&gt;false}], "numberOfBeats"=&gt;0, "divisions"=&gt;8}], "active"=&gt;false, "signature"=&gt;4, "representation"=&gt;"fraction"}, {"label"=&gt;"Synth", "img"=&gt;"synth.png", "mute"=&gt;true, "sample"=&gt;"ambass.mp3", "measures"=&gt;[{"label"=&gt;"0/4", "beats"=&gt;[{"selected"=&gt;false}, {"selected"=&gt;false}, {"selected"=&gt;false}, {"selected"=&gt;false}], "numberOfBeats"=&gt;0, "divisions"=&gt;8}], "active"=&gt;true, "signature"=&gt;4, "representation"=&gt;"fraction"}], "song"=&gt;{"title"=&gt;"1234", "content"=&gt;"{\"title\":\"1234\",\"content\":\"{\\\"title\\\":\\\"\\\",\\\"content\\\":\\\"\\\",\\\"user\\\":\\\"\\\",\\\"components\\\":[{\\\"label\\\":\\\"Snare\\\",\\\"img\\\":\\\"snare.png\\\",\\\"mute\\\":false,\\\"sample\\\":\\\"808_sd.m4a\\\",\\\"measures\\\":[{\\\"label\\\":\\\"0/4\\\",\\\"beats\\\":[{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false}],\\\"numberOfBeats\\\":0,\\\"divisions\\\":8}],\\\"active\\\":true,\\\"signature\\\":4,\\\"representation\\\":\\\"fraction\\\"},{\\\"label\\\":\\\"Hi Hat\\\",\\\"img\\\":\\\"hihat.png\\\",\\\"mute\\\":true,\\\"sample\\\":\\\"808_chh.m4a\\\",\\\"measures\\\":[{\\\"label\\\":\\\"0/4\\\",\\\"beats\\\":[{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false}],\\\"numberOfBeats\\\":0,\\\"divisions\\\":8}],\\\"active\\\":true,\\\"signature\\\":4,\\\"representation\\\":\\\"fraction\\\"},{\\\"label\\\":\\\"Kick Drum\\\",\\\"img\\\":\\\"kick.png\\\",\\\"mute\\\":true,\\\"sample\\\":\\\"808_bd.m4a\\\",\\\"measures\\\":[{\\\"label\\\":\\\"0/4\\\",\\\"beats\\\":[{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false}],\\\"numberOfBeats\\\":0,\\\"divisions\\\":8}],\\\"active\\\":false,\\\"signature\\\":4,\\\"representation\\\":\\\"fraction\\\"},{\\\"label\\\":\\\"Synth\\\",\\\"img\\\":\\\"synth.png\\\",\\\"mute\\\":true,\\\"sample\\\":\\\"ambass.mp3\\\",\\\"measures\\\":[{\\\"label\\\":\\\"0/4\\\",\\\"beats\\\":[{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false},{\\\"selected\\\":false}],\\\"numberOfBeats\\\":0,\\\"divisions\\\":8}],\\\"active\\\":true,\\\"signature\\\":4,\\\"representation\\\":\\\"fraction\\\"}]}\",\"user\":\"1\",\"components\":[{\"label\":\"Snare\",\"img\":\"snare.png\",\"mute\":false,\"sample\":\"808_sd.m4a\",\"measures\":[{\"label\":\"0/4\",\"beats\":[{\"selected\":false},{\"selected\":false},{\"selected\":false},{\"selected\":false}],\"numberOfBeats\":0,\"divisions\":8}],\"active\":true,\"signature\":4,\"representation\":\"fraction\"},{\"label\":\"Hi Hat\",\"img\":\"hihat.png\",\"mute\":true,\"sample\":\"808_chh.m4a\",\"measures\":[{\"label\":\"0/4\",\"beats\":[{\"selected\":false},{\"selected\":false},{\"selected\":false},{\"selected\":false}],\"numberOfBeats\":0,\"divisions\":8}],\"active\":true,\"signature\":4,\"representation\":\"fraction\"},{\"label\":\"Kick Drum\",\"img\":\"kick.png\",\"mute\":true,\"sample\":\"808_bd.m4a\",\"measures\":[{\"label\":\"0/4\",\"beats\":[{\"selected\":false},{\"selected\":false},{\"selected\":false},{\"selected\":false}],\"numberOfBeats\":0,\"divisions\":8}],\"active\":false,\"signature\":4,\"representation\":\"fraction\"},{\"label\":\"Synth\",\"img\":\"synth.png\",\"mute\":true,\"sample\":\"ambass.mp3\",\"measures\":[{\"label\":\"0/4\",\"beats\":[{\"selected\":false},{\"selected\":false},{\"selected\":false},{\"selected\":false}],\"numberOfBeats\":0,\"divisions\":8}],\"active\":true,\"signature\":4,\"representation\":\"fraction\"}]}"}}
  WARNING: Can't verify CSRF token authenticity
  Completed 401 Unauthorized in 1ms
  </code></pre>
  
  <p>Parameter with all the content removed:</p>
  
  <pre><code>Parameters: {"title"=&gt;"1234", "content"=&gt;"{\"title\":\"1234\",\"content\":\"{}", "user"=&gt;"1", "components"=&gt;[], "song"=&gt;{"title"=&gt;"1234", "content"=&gt;"{}"}}
  </code></pre>