mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Merge pull request #105 from raycohen/readme-fix-custom-attributes
fix custom attributes with scope readme section
This commit is contained in:
commit
21817bc795
10
README.md
10
README.md
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user