mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Reference scope by same name as serialization scope
By default, the serialization scope uses current_user, and you can now reference the scope as "current_user" in the serializer. If you override the scope using "serialization_scope" in your controller, it will use that method name instead.
This commit is contained in:
@@ -261,6 +261,13 @@ module ActiveModel
|
||||
|
||||
def initialize(object, options={})
|
||||
@object, @options = object, options
|
||||
|
||||
scope_name = @options[:scope_name]
|
||||
if scope_name && !respond_to?(scope_name)
|
||||
self.class.class_eval do
|
||||
define_method scope_name, lambda { scope }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def root_name
|
||||
|
||||
Reference in New Issue
Block a user