Created
September 14, 2018 09:50
-
-
Save tonyfg/cb29277a5bb604fc71d93d4803987e4f to your computer and use it in GitHub Desktop.
Org list JSON views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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