Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3619968
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:56:43+00:00 2026-05-18T22:56:43+00:00

Is there any quick way to make a form for embeds_many-embedded_in relation? I have

  • 0

Is there any quick way to make a form for embeds_many-embedded_in relation?
I have the following:

class Team
  include Mongoid::Document
  field :name, :type => String
  embeds_many :players
end

class Player
  include Mongoid::Document
  embedded_in :team, :inverse_of => :players
  field :name, :type => String
end

I want to create a form for team with embedded editing for players. Seen https://github.com/bowsersenior/formtastic_with_mongoid_tutorial but “TODO” there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:56:44+00:00Added an answer on May 18, 2026 at 10:56 pm

    I wrote the formtastic_with_mongoid_tutorial and unfortunately I haven’t figured out an easy way of dealing with embedded relations yet. What I’m doing now is building the embedded objects in the controller, and then passing the objects into a block. It would look kind of like this:

    = semantic_form_for @team do |form|
      = @team.players.each do |player|
        = form.inputs :for => [:players, player] do |player_form|
          = player_form.input :name
    

    Don’t forget to deal with nested attributes in Team:

    class Team
      include Mongoid::Document
      accepts_nested_attributes_for :players, 
        :allow_destroy => true, 
        # formtastic sends blank attributes to Mongoid models if you use checkboxes
        :reject_if => proc { |attributes| 
          attributes['name'].blank? && attributes['_destroy'].blank? 
        }
       # ...
    end
    

    It is definitely far from ideal. Wish I could be of more help, but maybe this will point you in the right direction. I’ll keep an eye out for better solutions and update the tutorial if/when I find any.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question... Is there any way to change the default behavior of a scrollbar
Is there any quick way to, given an executable file, create a Windows service
Are there any quick way to map some IDataReader to object without third party
Is there any quick way converting <?xml version=1.0?><response><id>0123456</id><userid>0123</userid> to <?xml version=1.0?> <response> <id> 0123456
Quick question, I was curious if there is any difference between a database table
Is there any way to check whether a file is locked without using a
Is there any way to capture the MouseDown even from the .NET 2.0 TextBox
Is there any known way of listing the WMI classes and their properties available
Is there any way to apply an attribute to a model file in ASP.NET
Is there a quick way in java to get the nest/recurse level? I'm writing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.