:
reply_to: json
json ( response_with (object))
class XYZController < ApplicationController
respond_to :html, :json
responders :jsons
def create
@xyz = Xyz.new( params[:xyz] )
@xyz.save
respond_with @xyz, :location=>@xyz.id.nil? ? "" : edit_xyz_url(@xyz)
end
end
json, :
module Responders
module JsonResponder
def to_json
raise error unless resourceful?
if get?
display resource
elsif has_errors?
display resource.errors, :status => :unprocessable_entity
elsif post?
display resource, :status => :created, :location => api_location
elsif put?
display resource, :status=>:ok, :location => api_location
elsif has_empty_resource_definition?
display empty_resource, :status => :ok
else
head :ok
end
end
end
end