Sha256: c25d90daef46587d2268b7ac9c541ab78eae18be78fb63a61ad670b68e567756

Contents?: true

Size: 943 Bytes

Versions: 1

Compression:

Stored size: 943 Bytes

Contents

class TbCore::Responder < ActionController::Responder

  def initialize(*)
    super

    # Don't require a :location parameter for redirecting
    if !@options.has_key?(:location)
      @options[:location] = nil
    end
  end

  # Override the common behavior for formats associated with APIs, such as :xml and :json.
  #
  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

  # Default responder only sends the basic errors array
  # This override also sends the translated labels for convenience
  #
  def json_resource_errors
    return Hash[resource.errors.messages.map do |attribute, messages|
      [attribute, {
        label: resource.class.human_attribute_name(attribute),
        messages: messages
      }]
    end]
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tb_core-1.3.10 lib/tb_core/responder.rb