Skip to content

Instantly share code, notes, and snippets.

@chrisnicola
Created October 3, 2011 03:17
Show Gist options
  • Select an option

  • Save chrisnicola/1258362 to your computer and use it in GitHub Desktop.

Select an option

Save chrisnicola/1258362 to your computer and use it in GitHub Desktop.
Serialization improvements for CouchRest Model
module CouchRest
module Serialization
extend ActiveSupport::Concern
include ActiveModel::Serialization
include ActiveModel::Serializers::JSON
include ActiveModel::Serializers::Xml
included do
class_attribute :include_root_in_json
self.include_root_in_json = false
end
def serializable_hash(options = nil)
options ||= {}
options[:except] ||= []
options[:except].push :_id
options[:methods] ||= []
options[:methods].push :id
options[:except] ||= []
options[:except].push :chapters
super(options)
end
def to_json
hash = as_json
hash.to_json
end
end
end
@chrisnicola
Copy link
Copy Markdown
Author

Added the include_root_in_json = false setting because Rails has a retarded default to true. Who includes the root in json???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment