I want to implement method in ruby to load images from the backend app but I don't know how. I have been trying with image_tag directly from a view to call the location /image/{imageId} or /image/{documentId} but no success obviously. This is what I get from the backend api:
[
  {
    "imageId": "1",
    "srcDocumentId": 10000,
    "scopes": null,
    "teiId": "",
    "name": "image",
    "headline": "Fig. 1. ",
    "description": "Fig. 1. GPA",
    "inBody": true,
    "image": "a long string",
    "internalUrl": "image.png",
    "source": "<figure xmlns=\"http://www.tei-c.org/ns/1.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xml:id=\"fig_3\"><head>Fig. 1. </head><figDesc>Fig. 1. GPA</figDesc><graphic coords=\"4,130.95,64.62,360.00,502.42\" type=\"bitmap\" url=\"image.png\"/></figure>",
    "ord": 0
  }
]
Any help would be appreciated. Even if you tell me only the logic on how should I handle this in a model and then at the view.
Edit:
Let's say I want to show the headline and description of the image first. I have this in document_helper.rb :
  def images_format(image)
    m = []
    m << [['Description:', image.description]] if image.description
    m << [
        ['Headline', image.headline]
    ] if image.headline.any?
    m
  end
in document.rb I have this:
 class Image
    include Mongoid::Document
    field :description, type: String
    field :headline, type: String
    field :image, type: String
    field :imageId, type: String
    field :image, type: String
    field :srcDocumentId, type: Integer
    field :internalUrl, type: String
    field :name , type: String
    field :internalUrl, type: String
    field :source, type: String
  end
and also this:
 embeds_one :image, class_name: 'Document::Image'
  embeds_one :image, class_name: 'Document::Image'
and in the view document_show.haml I put:
.document__body= images_format(@document.image)
I get this error: undefined method 'description' for nil:NilClass
