Skip to content

Instantly share code, notes, and snippets.

@tonyfg
Created September 14, 2018 09:50
Show Gist options
  • Save tonyfg/cb29277a5bb604fc71d93d4803987e4f to your computer and use it in GitHub Desktop.
Save tonyfg/cb29277a5bb604fc71d93d4803987e4f to your computer and use it in GitHub Desktop.
Org list JSON views
# app/views/organizations/index.json.jbuilder
json.array! @organizations, partial: 'organizations/organization', as: :organization
# app/views/organizations/_organization.json.jbuilder
json.extract! organization, :id, :name, :address, :contact_name, :contact_phone, :created_at, :updated_at
json.url organization_url(organization, format: :json)
json.hqs organization.hqs do |hq|
json.extract! hq, :id, :name
json.country hq.country.name
json.store_count hq.stores.count
json.stores hq.stores do |store|
json.extract! store, :id, :name
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment