Coder Social home page Coder Social logo

Comments (5)

Sutto avatar Sutto commented on July 26, 2024

Interesting - I'll take a look into how they handle the detection now and see how hard it would be to integrate into RP

from rocket_pants.

icem avatar icem commented on July 26, 2024

For people on rails 4.2 looking for easy workaround while issue not fixed:
I added this to initializers folder:

# Extracted from old active_model_serializers 0.8
# This patch fixes rocket_pants 1.11.0 compatibility with active_model_serializers 0.9
module ActiveModel::SerializerSupport
  extend ActiveSupport::Concern

  module ClassMethods #:nodoc:
    if "".respond_to?(:safe_constantize)
      def active_model_serializer
        "#{self.name}Serializer".safe_constantize
      end
    else
      def active_model_serializer
        begin
          "#{self.name}Serializer".constantize
        rescue NameError => e
          raise unless e.message =~ /uninitialized constant/
        end
      end
    end
  end

  # Returns a model serializer for this object considering its namespace.
  def active_model_serializer
    self.class.active_model_serializer
  end

  alias :read_attribute_for_serialization :send
end

module ActiveModel::ArraySerializerSupport
  def active_model_serializer
    ActiveModel::ArraySerializer
  end
end

Array.send(:include, ActiveModel::ArraySerializerSupport)
Set.send(:include, ActiveModel::ArraySerializerSupport)

{
    :active_record => 'ActiveRecord::Relation',
    :mongoid => 'Mongoid::Criteria'
}.each do |orm, rel_class|
  ActiveSupport.on_load(orm) do
    include ActiveModel::SerializerSupport
    rel_class.constantize.send(:include, ActiveModel::ArraySerializerSupport)
  end
end

Be sure to remove this code when issue will be fixed.

from rocket_pants.

Sutto avatar Sutto commented on July 26, 2024

There is a potential integration point for this in ActiveModel::Serializer.serializer_for, but I want to test compatibility etc before implementing it first.

from rocket_pants.

Sutto avatar Sutto commented on July 26, 2024

For a start, given there is a work around for this - that is to say, you can manually set :serializer or define your own active_model_serializer method, I'm going to leave this out of 1.12 to avoid accidentally breaking stuff.

I'll retag this to 1.13, and take a look for that in the near future.

Again - patches / specs welcome :)

from rocket_pants.

SirRawlins avatar SirRawlins commented on July 26, 2024

Just a note, but I'm experimenting with bringing RP up to spec with AMS 0.10.x which has even further interface changes above and beyond 0.9.x

I'll let you know how I get on.

from rocket_pants.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.