title: Writing to Rails with a JSON API
body: <p>I've been trying to write to a regular one model rails app from <a href="https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en" rel="noreferrer">POSTman</a> for a few days now, and can't figure out how to do it, or find any information on how to do it. </p>
  
  <p>My app has a User model with a name field. All I'm trying to do is change the name remotely via JSON using POSTman. </p>
  
  <p>Any help on how to do this is appreciated, including a link to a basic resource on how to do it. </p>
  
  <p>I imagine this is pretty basic.</p>
  
  <p>EDIT: here is a screenshot from the POSTman output</p>
  
  <p><img src="https://i.stack.imgur.com/e9ffB.png" alt="enter image description here"></p>
  
  <p>EDIT 2:</p>
  
  <p>from server log:</p>
  
  <pre><code>Started PUT "/users/1.json" for 127.0.0.1 at 2013-07-17 16:53:36 -0400
  Processing by UsersController#update as JSON
    Parameters: {"name"=&gt;"Jeff", "id"=&gt;"1"}
    User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", "1"]]
     (0.1ms)  begin transaction
     (0.1ms)  commit transaction
  Completed 204 No Content in 3ms (ActiveRecord: 0.4ms)
  </code></pre>
  
  <p>The transaction is happening, but the record isn't actually being updated. Do I need to change something in the controller? It's just a regular rails generated controller with no changes. </p>
  
  <p>EDIT 3:</p>
  
  <p>Here is my output from just going to <code>http://localhost:3000/users/1.json</code></p>
  
  <pre><code>{
  "created_at": "2013-07-02T21:51:22Z",
  "id": 1,
  "name": "Arel",
  "updated_at": "2013-07-02T21:51:22Z"
  }
  </code></pre>
  
  <p>Again, I've changed nothing from the scaffold, and I haven't been able to figure out how to format the JSON to nest it under user like the answer suggests. </p>
  
  <p>Here is the relevant part of my controller:</p>
  
  <pre><code># GET /users/1
    # GET /users/1.json
    def show
      @user = User.find(params[:id])
  
      respond_to do |format|
        format.html # show.html.erb
        format.json { render json: @user }
      end
    end
  
  # PUT /users/1
    # PUT /users/1.json
    def update
      @user = User.find(params[:id])
  
      respond_to do |format|
        if @user.update_attributes(params[:user])
          format.html { redirect_to @user, notice: 'User was successfully updated.' }
          format.json {  }
        else
          format.html { render action: "edit" }
          format.json { render json: @user.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p>I don't understand why this is so difficult. I'm just trying to update a name via JSON ...</p>