Module: ActiveModelSerializers
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- lib/active_model_serializers/logging.rb,
lib/active_model_serializers.rb,
lib/active_model_serializers/test.rb,
lib/active_model_serializers/model.rb,
lib/active_model_serializers/adapter.rb,
lib/active_model_serializers/railtie.rb,
lib/active_model_serializers/callbacks.rb,
lib/active_model_serializers/deprecate.rb,
lib/active_model_serializers/test/schema.rb,
lib/active_model_serializers/adapter/base.rb,
lib/active_model_serializers/adapter/json.rb,
lib/active_model_serializers/adapter/null.rb,
lib/active_model_serializers/json_pointer.rb,
lib/active_model_serializers/lookup_chain.rb,
lib/active_model_serializers/deserialization.rb,
lib/active_model_serializers/test/serializer.rb,
lib/active_model_serializers/adapter/json_api.rb,
lib/active_model_serializers/adapter/attributes.rb,
lib/active_model_serializers/adapter/json_api/link.rb,
lib/active_model_serializers/adapter/json_api/meta.rb,
lib/active_model_serializers/serializable_resource.rb,
lib/active_model_serializers/serialization_context.rb,
lib/active_model_serializers/adapter/json_api/error.rb,
lib/active_model_serializers/adapter/json_api/jsonapi.rb,
lib/active_model_serializers/register_jsonapi_renderer.rb,
lib/active_model_serializers/adapter/json_api/relationship.rb,
lib/active_model_serializers/adapter/json_api/deserialization.rb,
lib/active_model_serializers/adapter/json_api/pagination_links.rb,
lib/active_model_serializers/adapter/json_api/resource_identifier.rb
Overview
Based on discussion in github.com/rails/rails/pull/23712#issuecomment-184977238, the JSON API media type will have its own format/renderer.
> We recommend the media type be registered on its own as jsonapi when a jsonapi Renderer and deserializer (Http::Parameters::DEFAULT_PARSERS) are added.
Usage:
ActiveSupport.on_load(:action_controller) do
require 'active_model_serializers/register_jsonapi_renderer'
end
And then in controllers, use ‘render jsonapi: model` rather than `render json: model, adapter: :json_api`.
For example, in a controller action, we can: respond_to do |format|
format.jsonapi { render jsonapi: model }
end
or
render jsonapi: model
No wrapper format needed as it does not apply (i.e. no ‘wrap_parameters format: [jsonapi]`)
Defined Under Namespace
Modules: Adapter, Callbacks, Deprecate, Deserialization, JsonPointer, Jsonapi, Logging, LookupChain, Test Classes: Model, Railtie, SerializableResource, SerializationContext
Class Attribute Summary collapse
-
.logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
- .config ⇒ Object
-
.default_include_directive ⇒ JSONAPI::IncludeDirective
Memoized default include directive.
-
.location_of_caller ⇒ Object
The file name and line number of the caller of the caller of this method.
- .silence_warnings ⇒ Object
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
19 20 21 |
# File 'lib/active_model_serializers.rb', line 19 def logger @logger end |
Class Method Details
.config ⇒ Object
22 23 24 |
# File 'lib/active_model_serializers.rb', line 22 def self.config ActiveModel::Serializer.config end |
.default_include_directive ⇒ JSONAPI::IncludeDirective
Memoized default include directive
37 38 39 |
# File 'lib/active_model_serializers.rb', line 37 def self.default_include_directive @default_include_directive ||= JSONAPI::IncludeDirective.new(config.default_includes, allow_wildcard: true) end |
.location_of_caller ⇒ Object
The file name and line number of the caller of the caller of this method.
27 28 29 30 31 32 33 |
# File 'lib/active_model_serializers.rb', line 27 def self.location_of_caller caller[1] =~ /(.*?):(\d+).*?$/i file = Regexp.last_match(1) lineno = Regexp.last_match(2).to_i [file, lineno] end |
.silence_warnings ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/active_model_serializers.rb', line 41 def self.silence_warnings original_verbose = $VERBOSE $VERBOSE = nil yield ensure $VERBOSE = original_verbose end |