mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Add @options back into serializers to maintain the functionality of render :json as noted in the docs
This functionality used to exist in v0.8.1. This adds the ability to pass other options that will be usable in the serializer via the options accessor. This works by adding an attr_accessor for options so it is available and is set by the remaining options in the provided options hash during initialization.
This commit is contained in:
@@ -20,7 +20,7 @@ module ActiveModel
|
||||
@each_serializer = options[:each_serializer]
|
||||
@options = options.merge(root: nil)
|
||||
end
|
||||
attr_accessor :object, :root, :meta_key, :meta
|
||||
attr_accessor :object, :root, :meta_key, :meta, :options
|
||||
|
||||
def json_key
|
||||
if root.nil?
|
||||
|
||||
@@ -106,8 +106,9 @@ end
|
||||
@root = options.fetch(:root, self.class._root)
|
||||
@meta_key = options[:meta_key] || :meta
|
||||
@meta = options[@meta_key]
|
||||
@options = options.reject{|k,v| [:scope, :root, :meta_key, :meta].include?(k) }
|
||||
end
|
||||
attr_accessor :object, :scope, :meta_key, :meta, :root
|
||||
attr_accessor :object, :scope, :meta_key, :meta, :root, :options
|
||||
|
||||
def json_key
|
||||
if root == true || root.nil?
|
||||
|
||||
Reference in New Issue
Block a user