How to get the displayed result of the controller’s action without visiting a web page?

As part of the deployment process of our rails 2.3 application, I would like to save static versions of our error pages in a shared folder. How to get the displayed result of the controller’s action without visiting a web page? I know that this can be done because functional tests do this - if I say

get :errors, :id => 404 

then the body is in @ response.body. I suppose I could just copy the code from ActionController :: TestCase, but I hope there is an easier way to do this.

+1
source share
1 answer

In the end, I just went into ActionController :: TestCase, and this is what I dug up:

 def get_content host, path, filename request = ActionController::Request.new 'HTTP_HOST' => host, 'REQUEST_URI' => path, 'REQUEST_METHOD' => 'GET', 'rack.input' => '', 'rack.url_scheme' => 'http' controller = ActionController::Routing::Routes.recognize(request).new response = ActionController::Response.new controller.process request, response return response.body end 
+1
source

Source: https://habr.com/ru/post/893637/


All Articles