Skip to content

Instantly share code, notes, and snippets.

@umar-webonise
Last active August 29, 2015 14:19
Show Gist options
  • Save umar-webonise/996da011c93033a0dd83 to your computer and use it in GitHub Desktop.
Save umar-webonise/996da011c93033a0dd83 to your computer and use it in GitHub Desktop.
Dynamic Fields for active_model_serializers
class YourDynamicModelSerializer < ActiveModel::Serializer
attributes :_id, :name
def _id
object._id.to_s
end
def attributes
fields = object.attributes
super.each do |attr_name, attr_val|
fields[attr_name] = attr_val
end
fields
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment