Skip to content
haxney edited this page Aug 21, 2011 · 4 revisions

https://github.com/nesquena/rabl/issues/88

class MyResponder < ActionController::Responder
  def to_format
    case
    when has_errors?
      controller.response.status = :unprocessable_entity
    when post?
      controller.response.status = :created
    end

    default_render
  rescue ActionView::MissingTemplate => e
    api_behavior(e)
  end
end

and then in the controller:

class UsersController < ApplicationController
  respond_to :json, :xml, :html

  def update
    @user.update_attributes(params[:user])
    respond_with(@user, :responder => MyResponder)
  end
end