Skip to content

Instantly share code, notes, and snippets.

@benmoss
Last active January 3, 2016 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benmoss/8460895 to your computer and use it in GitHub Desktop.
Save benmoss/8460895 to your computer and use it in GitHub Desktop.
module ActiveModel
class Serializer
module Associations
class HasOne < Config
def root
if root = option(:root)
root
elsif polymorphic?
polymorphic_name.pluralize.to_sym
else
@name.to_s.pluralize.to_sym
end
end
def polymorphic_key
polymorphic_name.to_sym
end
private
def polymorphic_name
associated_object.active_model_serializer.name.demodulize.gsub("Serializer", "").underscore
end
end
end
end
end
class Admin
def active_model_serializer
SuperUserSerializer
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment