fabrik42/acts_as_api — Issue #46: Issue with rendering MessagePack
Author: masterkain
Created: 2011-11-30 03:49:11+00:00
State: open

Hello,
I followed the instruction of the wiki in order to add MessagePack support.

First I had to add the corresponding entry in initializers/mime_types.rb, something that's not written on the wiki, this is the code:

Mime::Type.register "application/messagepack", :mpac

Then in controller I have this (Rails 3.2, git master, relevant bits):

class InternalsController < ApplicationController
self.responder = ActsAsApi::Responder
respond_to :json, :xml, :mpac

def user_info
respond_with(@owner, api_template: :v2_private)
end

The problem is that Rails is trying to render a messagepack view.

# config/initializers/acts_as_api.rb

# Tell acts_as_api that it should accept an additional API format.
ActsAsApi::Config.accepted_api_formats << :mpac

# Add MessagePack as a Rails renderer.
ActionController::Renderers.add :mpac do |object, options|
self.content_type ||= Mime::MPAC
self.response_body = MessagePack.pack(object)
end

# MessagePack doesn't come with the ability to serialize a TimeWithZone, monkey patch.
module ActiveSupport
class TimeWithZone
def to_msgpack(out = '')
self.to_s.to_msgpack(out)
end
end
end

RSpec tests fails:

Failure/Error: get 'user_info', format: 'mpac', k: string
ActionView::MissingTemplate:
Missing template internals/user_info, application/user_info with {:locale=>[:en, :en], :formats=>[:mpac], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in:
* "#"

Am I missing something? Thanks!