Last active
          August 29, 2015 14:19 
        
      - 
      
- 
        Save umar-webonise/996da011c93033a0dd83 to your computer and use it in GitHub Desktop. 
    Dynamic Fields for active_model_serializers
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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