Newer
Older
dmpopidor / app / views / api / v0 / guidances / show.json.jbuilder
# builds a json response to api querry for a specific guidance

json.prettify!

json.guidance do
  json.id     @guidance.id
  json.text   @guidance.text
  json.updated_at   @guidance.updated_at

  # each guidance may be associated with many guidance groups
  @guidance_groups = @guidance.guidance_groups
  unless @guidance_groups.empty?
    json.guidance_groups @guidance_groups do |guidance_group|
      json.name       guidance_group.name
      json.id         guidance_group.id

      # for each template associated with the guidance group, list the template name
      @templates = guidance_group.dmptemplates
      # if the template is empty, instead use all avalable templates
      if @templates.empty?
        @templates = Dmptemplate.all
      end
      json.templates @templates do |template|
        json.title    template.title
      end
      json.optional   guidance_group.optional_subset
      json.updated    guidance_group.updated_at
    end
  end
end