Module: Carbonyte::Concerns::Serializable
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationController
- Defined in:
- app/controllers/carbonyte/concerns/serializable.rb
Overview
The Serializable concern helps with JSON:API serialization
Instance Method Summary collapse
-
#include_option ⇒ Object
Default include options for serializers.
-
#serialize(object, serializer_class: nil, status: :ok) ⇒ Object
Helper method to render json responses.
-
#serializer_options ⇒ Object
Default options for serializers.
Instance Method Details
#include_option ⇒ Object
Default include options for serializers
34 35 36 37 38 |
# File 'app/controllers/carbonyte/concerns/serializable.rb', line 34 def include_option return [] unless params[:include] params[:include].split(',').map(&:to_sym) end |
#serialize(object, serializer_class: nil, status: :ok) ⇒ Object
Helper method to render json responses
18 19 20 21 |
# File 'app/controllers/carbonyte/concerns/serializable.rb', line 18 def serialize(object, serializer_class: nil, status: :ok) serializer_class ||= serializer_for(object) render json: serializer_class.new(object, ).serializable_hash.to_json, status: status end |
#serializer_options ⇒ Object
Default options for serializers
24 25 26 27 28 29 30 31 |
# File 'app/controllers/carbonyte/concerns/serializable.rb', line 24 def { include: include_option, params: { current_user: current_user } } end |