2010-07-13 00:46:17 +00:00
|
|
|
module Locomotive
|
2011-11-09 01:35:59 +00:00
|
|
|
class Responder < ::ActionController::Responder
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-13 23:37:02 +00:00
|
|
|
include ::Responders::FlashResponder
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-11-10 12:29:59 +00:00
|
|
|
# by default flash_now messages if the resource has errors
|
|
|
|
def set_flash_now?
|
|
|
|
super || has_errors?
|
|
|
|
end
|
2010-07-13 00:46:17 +00:00
|
|
|
|
2011-11-10 21:41:20 +00:00
|
|
|
def api_behavior(error)
|
|
|
|
puts "api_behavior here"
|
|
|
|
|
|
|
|
super
|
|
|
|
|
|
|
|
puts "api_behavior there"
|
|
|
|
end
|
|
|
|
|
|
|
|
# def api_behavior(error)
|
|
|
|
# raise error unless resourceful?
|
|
|
|
#
|
|
|
|
# if get?
|
|
|
|
# display resource
|
|
|
|
# elsif post?
|
|
|
|
# display resource, :status => :created, :location => api_location
|
|
|
|
# elsif has_empty_resource_definition?
|
|
|
|
# display empty_resource, :status => :ok
|
|
|
|
# else
|
|
|
|
# head :ok
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
2011-11-10 12:29:59 +00:00
|
|
|
def to_json
|
2010-07-13 00:46:17 +00:00
|
|
|
if get?
|
|
|
|
display resource
|
|
|
|
elsif has_errors?
|
2011-11-10 12:29:59 +00:00
|
|
|
display resource.errors, :status => :unprocessable_entity
|
2010-07-13 00:46:17 +00:00
|
|
|
elsif post?
|
2011-11-10 12:29:59 +00:00
|
|
|
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
|
2010-07-13 00:46:17 +00:00
|
|
|
else
|
2011-11-10 12:29:59 +00:00
|
|
|
head :ok
|
2010-07-13 00:46:17 +00:00
|
|
|
end
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-11-10 12:29:59 +00:00
|
|
|
# def api_behavior(error)
|
|
|
|
# raise error unless resourceful?
|
|
|
|
#
|
|
|
|
# # generate flash messages
|
|
|
|
# set_flash_message!
|
|
|
|
#
|
|
|
|
# if get?
|
|
|
|
# display resource
|
|
|
|
# elsif has_errors?
|
|
|
|
# display({ :errors => resource.errors, :model => controller.send(:resource_instance_name), :alert => controller.flash[:alert] })
|
|
|
|
# elsif post?
|
|
|
|
# display resource, :status => :created, :location => resource_location
|
|
|
|
# else
|
|
|
|
# display({ :notice => controller.flash[:notice] })
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# controller.flash.discard # reset flash messages !
|
|
|
|
# end
|
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
end
|
2011-11-09 01:35:59 +00:00
|
|
|
end
|