This project is archived and is in readonly mode.

#5270 ✓duplicate
Lawrence Pit

respond_with sends back wrong json errors response

Reported by Lawrence Pit | August 2nd, 2010 @ 07:54 AM

Using Rails 3 RC: when posting/putting data, and a validation fails, an "errors" array is send back. This works if the format is xml, but if the format is json then it sends back an incorrect response when using +respond_with+.

Example given:

class ProjectsController < ApplicationController
  respond_to :xml, :json

  def create
    @project = Project.create(params[:project])
    respond_with(@project)
  end
end

class Project < ActiveRecord::Base
  validates :name, :presence => true
end

then:

$ curl -v -X POST http://localhost:3000/projects.json

< HTTP/1.1 422 Unprocessable Entity
["Name can't be blank"]

It should respond with:

{"errors" => ["Name can't be blank"]}

Note that ActiveResource expects errors in this format.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages