mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
fix custom attributes with scope readme section
This commit is contained in:
parent
dbde02d647
commit
63465fda68
10
README.md
10
README.md
@ -222,10 +222,14 @@ class Person < ActiveRecord::Base
|
|||||||
def full_name
|
def full_name
|
||||||
"#{first_name} #{last_name}"
|
"#{first_name} #{last_name}"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class PersonSerializer < ActiveModel::Serializer
|
||||||
|
attributes :first_name, :last_name
|
||||||
|
|
||||||
def attributes
|
def attributes
|
||||||
hash = super(options)
|
hash = super
|
||||||
hash["full_name"] = full_name if scope.admin?
|
hash["full_name"] = object.full_name if scope.admin?
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user