Ruby on Rails Advanced JSON Serialization

前端 未结 7 925
闹比i
闹比i 2020-12-13 02:53

I\'m looking to render an index of all articles along with a full article via JSON in my rails app, but I\'m having a little trouble figuring out how to do it.

Here

相关标签:
7条回答
  • 2020-12-13 03:36

    You hint at the solution in your question. You most likely want to build up a hash to render to JSON. The preferred way of doing this now is by providing an implementation for the as_json method. as_json provides a formal means of customizing to_json output by building up a hash containing the data you wish to encode.

    A more thorough treatment of how as_json and to_json interact can be found on Jonathan Julian's weblog.

    0 讨论(0)
提交回复
热议问题