Last active
          August 29, 2015 14:24 
        
      - 
      
- 
        Save tiomoreno/fd5904491d98670c7173 to your computer and use it in GitHub Desktop. 
    active record extension
  
        
  
    
      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
    
  
  
    
  | module ActiveRecordExtension | |
| extend ActiveSupport::Concern | |
| def as_json(options = {}) | |
| begin | |
| serializer_class = "#{self.class}Serializer" | |
| serializer_class.constantize.new(self, {root: false}) | |
| rescue LoadError => e | |
| super(options) | |
| end | |
| end | |
| end | |
| ActiveRecord::Base.send(:include, ActiveRecordExtension) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment