I have two controllers: controller A and controller B and I'm calling a controller A's actions from Controller B like this:
AController.dispatch(:get, request, response)
my question is - is it a better practice to pass on a copy of the request response objects?
What is the correct way of using ActionController::dispatch method
Clarification I have to call controller B from controller A its a constraint... now the question was specifically regarding 'dispatch'...
You shouldn't be using it at all in application code.
ActionController.dispatchis the internal implementation of how Rails calls your controller as middleware and how the depreachiated controller tests were implemented. Rails doesn't actually clearly destinguish between the components that are a part of the makeup framework and its "public APIs" that are intended for use in your application but this definitely the former.The main reasons you should not be using it in this situation is that it breaks the entire idea of what controller should be doing - responding to HTTP requests when they are hit by the router.
It creates a strong coupling between different controllers (that should not be coupled) and can have very unexpected side effects.
If what you're looking to do is reuse code there are also much better options: