ruby 在rails中为具有关联的对象生成JSON

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 在rails中为具有关联的对象生成JSON相关的知识,希望对你有一定的参考价值。

def setup_custom_json_for_datagrid(shops)
    json_data = shops.to_json(only: [:id, :name], include: { concept: { only: :name, include: { chain: { only: :name} } } })
    jsonResponse = "{\"current\": #{params[:current]}, \"rowCount\": #{params[:rowCount]}, \"rows\": #{json_data}, \"total\": #{shops.length}}"
  end

以上是关于ruby 在rails中为具有关联的对象生成JSON的主要内容,如果未能解决你的问题,请参考以下文章