Class: TbCore::Responder

Inherits:
ActionController::Responder
  • Object
show all
Defined in:
lib/tb_core/responder.rb

Instance Method Summary collapse

Constructor Details

#initializeResponder

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_behaviorObject

Override the common behavior for formats associated with APIs, such as :xml and :json.

Raises:

  • (MissingRenderer)


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_errorsObject

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