简体   繁体   English

Rails-字符串的response_with(@object)

[英]Rails - respond_with(@object) to string

I have controller which uses respond_with and jbuilder to render some JSON data. 我有一个控制器,它使用respond_with和jbuilder呈现一些JSON数据。

I need to save rendered string somewhere. 我需要将渲染的字符串保存在某个地方。 Normally I can use render_to_string but this will require me to pass template argument and locals . 通常我可以使用render_to_string但这需要我传递template参数和locals变量。

What I need is to get access to string rendered using respond_with(@object) , for example: {"id": 1, "name": 2} and save it somewhere 我需要访问的是使用respond_with(@object)呈现的字符串,例如: {"id": 1, "name": 2}并将其保存在某个位置

any ideas? 有任何想法吗?

Then you may need to look at this SO post - 然后,您可能需要查看 SO帖子-

Also check this link http://apidock.com/rails/ActionController/Base/render_to_string . 还要检查此链接http://apidock.com/rails/ActionController/Base/render_to_string This clearly shows the options parameters essential. 这清楚地显示了必需的选项参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM