Ruby on Rails Friday, February 1, 2013

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.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/AzWrkB1iXosJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment