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
15
lib/grape/formatters/active_model_serializers.rb
Normal file
15
lib/grape/formatters/active_model_serializers.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# A Grape response formatter that can be used as 'formatter :json, Grape::Formatters::ActiveModelSerializers'
|
||||
#
|
||||
# Serializer options can be passed as a hash from your Grape endpoint using env[:active_model_serializer_options],
|
||||
# or better yet user the render helper in Grape::Helpers::ActiveModelSerializers
|
||||
module Grape
|
||||
module Formatters
|
||||
module ActiveModelSerializers
|
||||
def self.call(resource, env)
|
||||
serializer_options = {}
|
||||
serializer_options.merge!(env[:active_model_serializer_options]) if env[:active_model_serializer_options]
|
||||
ActiveModel::SerializableResource.new(resource, serializer_options).to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user