在视图中发布模型中的字段

时间:2018-10-04 19:40:39

标签: ruby-on-rails ruby mongodb mongoid

我有一个Document.rb模型,并在其中创建了另一个类图像:

 class Image
    include Mongoid::Document

    field :imageId, type: String

    field :srcDocumentId, type: Integer

    field :scopes, type: String

    field :teiId, type: String

    field :name , type: String

    field :headline, type: String

    field :description, type: String

    field :inBody, type: Boolean

    field :image, type: String

    field :internalUrl, type: String

    field :source, type: String

    field :ord, type: Integer

  end

我有这个:

 PdsBackend.document_images(external_id).each do |image|
 doc.images << Image.new(image)
 end

在另一类文档中:

  class Document
    include Mongoid::Document

  field :external_document_id, type: String

  field :file_name, type: String

  embeds_one :image, class_name: 'Document::Image'

,并且在pds_backend.rb中,我已经定义了:

def document_images(document_id)
    with_login do
    expect_success { self.class.get("/image/#{document_id}")}
  end
end

在视图中,当我想显示从后端获得的信息时:

   %h1.document__body= (@document.image)

我想在前端显示名称,标题和图像字符串,但我不知道如何定义图像

0 个答案:

没有答案