Skip to content

Set serialization_scope and scope is nil in serializer #2144

@crustyratfink

Description

@crustyratfink

Expected behavior vs actual behavior

Expect to set
serialization_scope :view_context
in application_controller.rb

And in serializer:
delegate :current_user, to: :scope

and then access current_user in serializer.

Actual:
IssueSerializer#current_user delegated to scope.current_user, but scope is nil:...

Steps to reproduce

See above:
Set serialization_scope :view_context in application_controller.rb, delegate current_user to scope in serializer, try to access current_user in serializer.

Environment

ActiveModelSerializers Version (commit ref if not on tag): 0.10.6

Output of ruby -e "puts RUBY_DESCRIPTION": 2.3.1p112

OS Type & Version: OSX 10.12.4

Integrated application and version (e.g., Rails, Grape, etc): Rails 5.1

Backtrace

(e.g., provide any applicable backtraces from your application)
Module::DelegationError (IssueSerializer#current_user delegated to scope.current_user, but scope is nil: #<IssueSerializer:0x007fbd370c8bf8 @object=#<Issue id: 22, title: ...data removed>, @scope=nil, @root=nil, @polymorphic=false, @meta_key=:meta, @meta=nil, @wrap_in_array=nil, @only=nil, @except=nil, @key_format=nil, @context=nil, @namespace=nil, @serialization_options={}>):

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions