Adding new documents embedded_in to a pre-existing document

I am trying to teach myself Rails for my mobile development course. The instructor uses python and Jinja, but said we can use anything, so myself. For the upcoming project, we need to create an application that uses a NoSQL database. I am using MongoDB, especially mongoid.

I have two Models, a verb and a tense, where the verb lays several tenses. I want to have a link on the page with the show verb in a new form where you fill in the new tense to insert in the specified verb.

I found many examples using nested forms where you create both at the same time, but not where you create a new document to embed in an existing one.

Since I'm new to rails, I might be wrong about being wrong, so I can't seem to find what I'm looking for. Any help or answer or direction to look would be appreciated.

Here are the models I have installed. If I need to provide more, just let me know.

class Verb
  include Mongoid::Document
  embeds_many :tenses, class_name: "Tense"
  field :first, type: String
  field :second, type: String
  field :third, type: String
  field :fourth, type: String

  index({first: 1})
end

class Tense
  include Mongoid::Document
  embedded_in :verb, :inverse_of => :tenses
  field :name, type: String
  field :abbrv, type: String
  field :voice, type: String
  field :mood, type: String
  index({abbrv: 1})
end

      

+3


source to share





All Articles