Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

respond_with sends back wrong json errors response

#5270

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.

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

State: duplicate
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Neeraj Singh
    Neeraj Singh
    • State changed from new to duplicate
    • Importance changed from to Low

    August 2nd, 2010 @ 02:25 PM