mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 22:36:50 +00:00
* Fix #1759, Grape integration, adds serialization_context - `serialization_context` is added in grape formatter so grape continues to render models without an explicit call to the `render` helper method - Made it straightforward for subclasses to add other serializer options (such as `serialization_scope`). * Updated Grape tests to include: - paginated collections - implicit Grape serializer (i.e. without explicit invocation of `render` helper method) * Update Changelog with fixes.
18 lines
673 B
Ruby
18 lines
673 B
Ruby
# Helpers can be included in your Grape endpoint as: helpers Grape::Helpers::ActiveModelSerializers
|
|
|
|
module Grape
|
|
module Helpers
|
|
module ActiveModelSerializers
|
|
# A convenience method for passing ActiveModelSerializers serializer options
|
|
#
|
|
# Example: To include relationships in the response: render(post, include: ['comments'])
|
|
#
|
|
# Example: To include pagination meta data: render(posts, meta: { page: posts.page, total_pages: posts.total_pages })
|
|
def render(resource, active_model_serializer_options = {})
|
|
env[:active_model_serializer_options] = active_model_serializer_options
|
|
resource
|
|
end
|
|
end
|
|
end
|
|
end
|