我想用机架中间件打印模板的主体.下面是我的设置…… #config/initializers/response_timer.rb class ResponseTimer def initialize(app) @app = app end def call(env) status, headers, response = @app.call(env) [status, header
#config/initializers/response_timer.rb
class ResponseTimer
def initialize(app)
@app = app
end
def call(env)
status, headers, response = @app.call(env)
[status, headers, response.body]
end
end
#application.rb file
config.middleware.use "ResponseTimer"
当我提出请求domainname / students /我收到以下错误.
undefined method `each' for #<String:0xd69a2e0>
请帮助.
我通过将[status,headers,response.body]更改为[status,headers,[response.body]]来解决我自己的问题,将response.body放在数组中.