首页 \ 问答 \ Rails 4 MongoID嵌入式文档(Rails 4 MongoID embedded Documents)

Rails 4 MongoID嵌入式文档(Rails 4 MongoID embedded Documents)

我有以下型号

class Professional
  include Mongoid::Document
  field :first_name, type: String
  field :last_name, type: String
  field :company_name, type: String
  field :address, type: String


  validates :first_name, length: { minimum: 5, :message => "What" }, format: { with: /\A[a-zA-Z]+\z/, message: "only allows letters" }
end

我想要包含一个嵌入式文档,我可以存储多个办公地址。 我正在寻找以下DB的结构

{
  "first_name": "Harsha",
  "last_name": "MV",
  "company_name": "Mink7",
  "offices": [
    {
      "name": "Head Office",
      "address": "some address here"
    },
    {
      "name": "Off Site Office",
      "address": "some large address here"
    }
  ]
}

I have the following model

class Professional
  include Mongoid::Document
  field :first_name, type: String
  field :last_name, type: String
  field :company_name, type: String
  field :address, type: String


  validates :first_name, length: { minimum: 5, :message => "What" }, format: { with: /\A[a-zA-Z]+\z/, message: "only allows letters" }
end

I want to include a embedded documents where i can store multiple office address. Am looking for the following Structure of the DB

{
  "first_name": "Harsha",
  "last_name": "MV",
  "company_name": "Mink7",
  "offices": [
    {
      "name": "Head Office",
      "address": "some address here"
    },
    {
      "name": "Off Site Office",
      "address": "some large address here"
    }
  ]
}

原文:https://stackoverflow.com/questions/21375237
更新时间:2022-09-05 09:09

最满意答案

在这种情况下,你需要使用.twocolumns类来div没有你的标题,即像这样的h2元素

<div class="article">
    <h2>Biography</h2>
    <div class="twocolumns">
  <p>Lorem ipsum dolor sit amet,....

并重置p元素的默认marginpadding以使其更清晰。

p
{
    margin:0;
    padding:0;
}

所以基本上将.twocolumns类应用于那些要分成两列的元素。 在你的情况下,你不希望有标题。 所以把它从那里排除并把它放在外面。

JS小提琴


In that case you need to use the .twocolumns class to div that doesn't have your heading i.e. h2 element like this

<div class="article">
    <h2>Biography</h2>
    <div class="twocolumns">
  <p>Lorem ipsum dolor sit amet,....

and reset the default margin and padding for p element to make it more clear.

p
{
    margin:0;
    padding:0;
}

So basically apply .twocolumns class to those element which you want to break into two columns. In your case you doesn't want to have heading in that. So exclude it from there and put it outside.

JS Fiddle

相关问答

更多