mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
fix custom attributes with scope readme section
This commit is contained in:
parent
dbde02d647
commit
63465fda68
@ -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