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 5938589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:42:27+00:00 2026-05-22T15:42:27+00:00

So I have a simple application as in RailsCast about nested forms. and a

  • 0

So I have a simple application as in RailsCast about nested forms. and a problem is that when I submit the form (with survey and questions) the questions are not saved.

My models (Survey, that has many Questions):

class Survey
  include Mongoid::Document
  field :name
  has_many :questions, :dependent => :destroy
  accepts_nested_attributes_for :questions, :allow_destroy => true
end

class Question
  include Mongoid::Document
  field :content
  belongs_to :survey
end

and Survey Controller:

def new
    @survey = Survey.new
    3.times {@survey.questions.build}
....

and a view:

<%= form_for(@survey) do |f| %>
    <%= f.fields_for :questions do |builder| %>
    <%= builder.label :content, "Question" %><br />
    <%= builder.text_area :content, :rows => 3 %><br />
    <%= builder.check_box :_destroy %>
    <%= builder.label :_destroy, "Remove Question" %>
    <% end %>
...

In my log I have:

    Started POST "/surveys" for 127.0.0.1 at 2011-05-24 13:26:51 +0400
  Processing by SurveysController#create as HTML
  Parameters: {"utf8"=>"G£ô", "authenticity_token"=>"tX0FfMiLbh1BwjuY4CuvAKt2UpTraY3vmdo58ocBnos=", "survey"=>{"name"=>"
Rails", "questions_attributes"=>{"0"=>{"content"=>"Are you fond of Rails?", "_destroy"=>"0"}, "1"=>{"content"=>"Rails is
 the best, ha?", "_destroy"=>"0"}, "2"=>{"content"=>"How many railscasts have you watched?", "_destroy"=>"0"}}}, "commit
"=>"Create Survey"}
MONGODB nested_attributes_development['surveys'].insert([{"name"=>"Rails", "_id"=>BSON::ObjectId('4ddb79dba5372914380000
69')}])
Redirected to http://localhost:3000/surveys/4ddb79dba537291438000069
  • 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-22T15:42:27+00:00Added an answer on May 22, 2026 at 3:42 pm

    The answer was found in google groups so I just duplicate it:

    MONGODB 
    nested_attributes_development['surveys'].insert([{"name"=>"Rails", 
    "_id"=>BSON::ObjectId('4ddb79dba5372914380000 
    69')}]) 
    

    This does not save to question collections which is not done with
    mongoid in default.
    Just add has_many :questions, :dependent => :destroy , :autosave =>
    true

    This should work.

    cf. http://mongoid.org/docs/upgrading.html for further details.

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

Sidebar

Related Questions

I have simple WinForms application where modifying Windows Registry. The problem is that in
I have a simple message box in a WPF application that is launched as
I have simple application, that shows list of many items, where user can display
I have a simple application that counts down to midnight and then plays a
I have written simple application with container-managed security. The problem is when I log
I have a simple application that consists of a HSlider and a list that
I have a very simple application with a form, a richedit and a menu.
Say I have a simple WCF application that the client calls in order to
I have simple web application called App that is secured with Windows Authentication. I
I have simple web application (asp.net - ajax) I have a web form which

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.