我正在开发一个新的 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?或者是否有另一种标准方法来完成上述操作(我不想编写模仿renderAPI 的自定义解决方案)?