我正在为它开发一个新的Rails应用程序和一个JSON API。我正在使用render
进行API响应编码,如此
render json: @images,
only: [:id, :size, :mime_type, :file_name, :created_at],
methods: methods
以上情况还可以,但是如果回复很好,那就太好了。谷歌搜索没有多大帮助,因为所有结果都显示JSON.pretty_generate
无法处理only
和methods
。
有没有办法用render
进行漂亮打印?或者是否有其他标准方法可以实现上述目标(我不想编写模仿render
API的自定义解决方案)?