Class: TbCore::Responder
- Inherits:
-
ActionController::Responder
- Object
- ActionController::Responder
- TbCore::Responder
- Defined in:
- lib/tb_core/responder.rb
Instance Method Summary collapse
-
#api_behavior ⇒ Object
Override the common behavior for formats associated with APIs, such as :xml and :json.
-
#initialize ⇒ Responder
constructor
A new instance of Responder.
-
#json_resource_errors ⇒ Object
Default responder only sends the basic errors array This override also sends the translated labels for convenience.
Constructor Details
#initialize ⇒ Responder
Returns a new instance of Responder.
3 4 5 6 7 8 9 10 |
# File 'lib/tb_core/responder.rb', line 3 def initialize(*) super # Don't require a :location parameter for redirecting if !@options.has_key?(:location) @options[:location] = nil end end |
Instance Method Details
#api_behavior ⇒ Object
Override the common behavior for formats associated with APIs, such as :xml and :json.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/tb_core/responder.rb', line 14 def api_behavior raise MissingRenderer.new(format) unless has_renderer? if get? display resource elsif post? || patch? display resource, :status => :created, :location => api_location else head :no_content end end |
#json_resource_errors ⇒ Object
Default responder only sends the basic errors array This override also sends the translated labels for convenience
28 29 30 31 32 33 |
# File 'lib/tb_core/responder.rb', line 28 def json_resource_errors return { :errors => resource.errors, :labels => resource.errors.keys.collect{ |attribute| resource.class.human_attribute_name(attribute) } } end |