Topic: Add a customer renderer

Hi,

I'm trying to include the support of Msgpack in Rails 3.2 but when I try to return a mpac response, I get an error concerning a missing template.

My renderer:

Mime::Type.register 'application/x-mpac', :mpac
ActionController::Renderers.add :mpac do |mpac, options|
  self.content_type ||= Mime::MPAC
  self.response_body  = mpac.respond_to?(:to_msgpack) ? mpac.to_msgpack : mpac
end

My controller:

class UsersController < ApplicationController
  respond_to :mpac, :json

  def show
    respond_with({ hello: 'world' })
  end
end

And my serializer:

require 'msgpack'

module ActiveModel
  module Serializers
    module MPAC
      extend ActiveSupport::Concern
      include ActiveModel::Serialization

      included do
        extend ActiveModel::Naming
      end

      def to_mpac(options = nil)
        serializable_hash(options).to_msgpack
      end
      alias_method :to_msgpack, :to_mpac

      def from_mpac(msg)
        MessagePack.unpack(msg)
      end
    end
  end
end

Anyone has an idea ?

Thanks.

Re: Add a customer renderer

Help sad