mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Grape formatter feature requested in #1258
- adds handling for when the returned resource is not serializable via ams - fix for when resource is an Array - Moves grape include to grape namespace. Changes Enumerable to Array because a plain hash is enumerable. - Add integration test - Refine scope of Grape version dependency - Assert that the response is equal to a manually defined JSON string - Add single module to include in Grape projects - Create a Serializable Resource to test rails-api from Grape - Update docs - Fix discrepency between ActiveRecord 4.0 - 4.1 and 4.2 - Updated Changelog - Remove parens from `render`, use `serializable` in all tests.
This commit is contained in:
committed by
John Hamelink
parent
614e349502
commit
d85a17bb33
16
lib/grape/helpers/active_model_serializers.rb
Normal file
16
lib/grape/helpers/active_model_serializers.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user