Version 0.10.6
Current implementation:
# lib/action_controller/serialization.rb
def namespace_for_serializer
@namespace_for_serializer ||= self.class.parent unless self.class.parent == Object
end
If self.class.parent is an Object (which is always true for class without namespace), #namespace_for_serializer returns nil instead of @namespace_for_serializer.
How is this a bug?
When the controller is not in any namespace, setting namespace_for_serializer doesn't have any effect.
Only redefining the method namespace_for_serializer or putting the controller in a namespace works.
I'm having the same issue when trying to set namespace_for_serializer in a controller that is not inside a namespace. I believe the OP is correct in that this is a bug because the logic ignores the @namespace_for_serializer value that was set in the controller only in the case when the controller is not inside a namespace. I can't think of a reason why this would be the desired behavior as this functionality is potentially useful on any controller not just one inside of a namespace.
As a workaround setting namespace on the actual render call does work.
render json: @post, namespace: Api::V2
I'm having the same issue, and to set namespace on action not working too for me.
Please open a new issue
Most helpful comment
When the controller is not in any namespace, setting
namespace_for_serializerdoesn't have any effect.Only redefining the method
namespace_for_serializeror putting the controller in a namespace works.