Skip to content

Instantly share code, notes, and snippets.

@dnsilva
Created July 2, 2015 07:07
Show Gist options
  • Save dnsilva/3e24e4ad0519558b2529 to your computer and use it in GitHub Desktop.
Save dnsilva/3e24e4ad0519558b2529 to your computer and use it in GitHub Desktop.
Generate json for object with associations rails
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment