Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Named scopes for ActiveRecord serialization methods (to_xml, to_json)
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
rails
spec
.gitignore
Gemfile
Gemfile.lock
README
Rakefile
VERSION
serialization_scopes.gemspec

README

== Serialization Scopes

Define scopes for XML/JSON serialization of your ActiveRecord models. Examples:

    # Model - column names: id, title, body, date, personal_notes, comments_count
    class Article < ActiveRecord::Base
      has_many :comments

      serialization_scope :author, :except => [:comments_count]
      serialization_scope :reader, :only => [:title, :body, :date], :include => [:comments]
    end

    Article.first.to_json
    # => {"id":1,"title":"Hello","body":"World","date":"2010-01-01","personal_notes":"Author's notes","comments_count":3}

    Article.first.to_json(:scope => :author)
    # => {"id":1,"title":"Hello","body":"World","date":"2010-01-01","personal_notes":"Author's notes"}

    Article.first.to_json(:scope => :author, :only => [:title])
    # => {"title":"Hello"}
Something went wrong with that request. Please try again.