mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Add AMS support to AR objects
This commit is contained in:
24
test/fixtures/poro.rb
vendored
Normal file
24
test/fixtures/poro.rb
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
class Model
|
||||
include ActiveModel::SerializerSupport
|
||||
|
||||
def initialize(hash={})
|
||||
@attributes = hash
|
||||
end
|
||||
|
||||
def read_attribute_for_serialization(name)
|
||||
@attributes[name]
|
||||
end
|
||||
end
|
||||
|
||||
class ModelSerializer < ActiveModel::Serializer
|
||||
attributes :attr1, :attr2
|
||||
|
||||
def attr2
|
||||
attr2 = object.read_attribute_for_serialization(:attr2)
|
||||
if scope
|
||||
attr2 + '-' + scope
|
||||
else
|
||||
attr2
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user