In rails, can I access response.body in a action before it returns?

后端 未结 4 1416
無奈伤痛
無奈伤痛 2021-01-05 11:08

In rails, can I access response.body in a action before it returns?

Say I want to do some final string replacements before it returns, can I get access to response.b

4条回答
  •  -上瘾入骨i
    2021-01-05 11:15

    Try after_filter in your controller.

    You should be able to edit your response.body from there. For me, I needed to remove some ASCII characters in the xml hence I did this.

    after_filter :sanitize_xml
    
    def sanitize_xml
       #clean the response body by accessing response.body
    

提交回复
热议问题