Merge pull request #105 from raycohen/readme-fix-custom-attributes

fix custom attributes with scope readme section
This commit is contained in:
José Valim 2012-07-28 10:21:39 -07:00
commit 21817bc795

View File

@ -222,10 +222,14 @@ class Person < ActiveRecord::Base
def full_name
"#{first_name} #{last_name}"
end
end
class PersonSerializer < ActiveModel::Serializer
attributes :first_name, :last_name
def attributes
hash = super(options)
hash["full_name"] = full_name if scope.admin?
hash = super
hash["full_name"] = object.full_name if scope.admin?
hash
end
end