silver-mx
7/4/2015 - 9:02 AM

JSON generation in rails for objects with associations

JSON generation in rails for objects with associations

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