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.
- .eager_load! ⇒ Object
-
.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.
24 25 26 |
# File 'lib/active_model_serializers.rb', line 24 def logger @logger end |
Class Method Details
.config ⇒ Object
27 28 29 |
# File 'lib/active_model_serializers.rb', line 27 def self.config ActiveModel::Serializer.config end |
.default_include_directive ⇒ JSONAPI::IncludeDirective
Memoized default include directive
42 43 44 |
# File 'lib/active_model_serializers.rb', line 42 def self.default_include_directive @default_include_directive ||= JSONAPI::IncludeDirective.new(config.default_includes, allow_wildcard: true) end |
.eager_load! ⇒ Object
54 55 56 57 |
# File 'lib/active_model_serializers.rb', line 54 def self.eager_load! super ActiveModel::Serializer.eager_load! end |
.location_of_caller ⇒ Object
The file name and line number of the caller of the caller of this method.
32 33 34 35 36 37 38 |
# File 'lib/active_model_serializers.rb', line 32 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
46 47 48 49 50 51 52 |
# File 'lib/active_model_serializers.rb', line 46 def self.silence_warnings original_verbose = $VERBOSE $VERBOSE = nil yield ensure $VERBOSE = original_verbose end |