title: How can can.js add a record to a Rails server?
body: <p>I am using Can.js to add a record to a Ruby on Rails server:</p>
  
  <pre><code>var Todo = can.Model({
    findAll : 'GET /todos',
    findOne : 'GET /todos/{id}',
    create  : 'POST /todos',
    update  : 'PUT /todos/{id}',
    destroy : 'DELETE /todos/{id}'
  }, {});
  
  Todo.prototype.description = function() {
      return this.name + " and " + this.complete;
  };
  
  Todo.findAll({}, function(todos) {
      todos.each(function(todo) {
          console.log(todo.name, todo.complete);
          console.log(todo.description());
      });
  });
  
  var todo = new Todo({name: "mow lawn"});
  
  todo.save();
  </code></pre>
  
  <p>the <code>findAll()</code> actually can get all the records, but the <code>save()</code> will insert a blank record.  I suspected it might be the <code>CSRF token</code>, but that shows as a warning, and if it didn't want to insert the record, it probably won't create any record at all, instead of adding a record with name being nothing?  (I also tried <code>var todo = new Todo({name: "mow lawn", complete: true});</code> and it is the same result).</p>
  
  <p>but the Rails server prints out on the terminal as:</p>
  
  <pre><code>Started POST "/todos" for 127.0.0.1 at 2013-04-12 08:16:05 -0700
  Processing by TodosController#create as JSON
    Parameters: {"name"=&gt;"mow lawn"}
  WARNING: Can't verify CSRF token authenticity
     (0.2ms)  begin transaction
    SQL (0.8ms)  INSERT INTO "todos" ("complete", "created_at", "name", "updated_at") 
  VALUES (?, ?, ?, ?)  [["complete", nil], ["created_at", Fri, 12 Apr 2013 15:16:05 UTC 
  +00:00], ["name", nil], ["updated_at", Fri, 12 Apr 2013 15:16:05 UTC +00:00]]
     (1.5ms)  commit transaction
  Completed 201 Created in 11ms (Views: 1.3ms | ActiveRecord: 2.5ms)
  </code></pre>
  
  <p>In the Chrome developer tool, I see in Network:</p>
  
  <pre><code>Request URL:http://localhost:3000/todos
  Request Method:POST
  
  part of header:
  Content-Type:application/x-www-form-urlencoded; charset=UTF-8
  
  form data:
  name:mow lawn
  </code></pre>
  
  <p>If my action is:</p>
  
  <pre><code>  def create
      p "params[:todo] is", params[:todo]
      @todo = Todo.new(params[:todo])
  
      respond_to do |format|
        if @todo.save
          format.html { redirect_to @todo, notice: 'Todo was successfully created.' }
          format.json { render json: @todo, status: :created, location: @todo }
        else
          format.html { render action: "new" }
          format.json { render json: @todo.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p>then terminal will show:</p>
  
  <pre><code>"params[:todo] is"
  nil
  </code></pre>
  
  <p>even though the terminal shows the standard Rails log:</p>
  
  <pre><code>Parameters: {"name"=&gt;"mow lawn"}
  </code></pre>