-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested serializers: undefined method #56
Comments
Hi. Yes, you should be using So: require 'oat/adapters/hal'
class AccountSerializer < Oat::Serializer
adapter Oat::Adapters::HAL
schema do
map_properties :id
entities :tasks, item.tasks do |task, task_serializer|
task_serializer.created_at task.created_at
end
end
end |
Sorry, that was the debug version I pasted in. When I use There is a |
The fix is to have another block for the serializer: require 'oat/adapters/hal'
class AccountSerializer < Oat::Serializer
adapter Oat::Adapters::HAL
schema do
map_properties :id
entities :tasks, item.tasks do |task, task_serializer|
task_serializer.properties do |props|
props.created_at task.created_at
end
end
end
end |
Yes. This should work to: task_serializer.property :created_at, task.created_at |
In following the readme to set up a nested serializer, I created this
AccountSerializer
:However, I'm getting the following error when running
AccountSerializer.new(Account.first).to_json
"undefined method 'created_at' for #<ActiveRecord::Associations::CollectionProxy []>"
Am I doing something wrong?
The text was updated successfully, but these errors were encountered: