Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
October 28, 2024
The key issue is likely related to how Rails automatically sets the serialization_scope. By default, Rails will call current_user to establish the context for serialization. We need to override this behavior.
class YourController < ApplicationController def serialization_scope nil # Prevents Rails from using current_user as the scope for serialization end end
This ensures that current_user is not invoked during the rendering process. Setting serialization_scope to nil disables the automatic attempt to assign a scope for JSON serialization.
Even if you’ve removed some callbacks, it’s good to ensure that any default Rails callbacks (like set_turbolinks_location_header_from_session) don’t interfere with the action.
class YourController < ApplicationController skip_before_action :set_turbolinks_location_header_from_session, :clean_temp_files def test _process_action_callbacks.map { |c| pp c.filter } render json: { hello: 'world' } end end
Skipping callbacks makes sure that Rails isn’t triggering any logic (like session handling or file cleanup) that could indirectly cause current_user to be called.