Questions tagged [nested-forms]

A form within another form, often in the ruby-on-rails environment.

This is a Rails gem for conveniently manage multiple nested models in a single form. It does so in an unobtrusive way through jQuery or Prototype.

This gem only works with Rails 3.

Nested forms are when a form is placed within another form, often in the environment.

As of HTML 5, the form element can't be nested. Check section 4.10.18, "Association of controls and forms" for more information.

The platform can also handle nested forms, like the example below:

<div class="form">
    <?php $this->renderPartial('_form', array('form'=>$form)); ?>
    <?php echo $form['user']; ?>
    <?php echo $form['profile']; ?>
    <?php echo $form['subformbuttons']; ?>
</div>

Check the section for general questions and details about forms.

1948 questions
11
votes
2 answers

Rails Nested Forms With Images

So I'm building a nested form with an Campaigns model and a Sites model where Campaigns has_many Sites. In my Campaigns form I have: <%= f.fields_for :sites do |builder| %> <%= render "site_fields", :f => builder %> <% end %> And then in the…
dshipper
  • 3,209
  • 3
  • 27
  • 41
11
votes
3 answers

React: how to use child FormItem components without getting Warning: validateDOMNesting:
cannot appear as a descendant of

Given the parent component, I am using a child component DynamicFieldSet that is a grouping of FormItems. But I am receiving the error: Warning: validateDOMNesting(...): cannot appear as a descendant of . See CreateTopic > Form > form >…
The Nomad
  • 6,385
  • 12
  • 58
  • 98
11
votes
3 answers

Rails 4 nested attributes not saving

I cannot seem to get nested attributes to save to the database. I am using Rails 4. Here are my models : class Answer < ActiveRecord::Base belongs_to :question end class Question < ActiveRecord::Base has_many :answers belongs_to :survey …
Michael
  • 680
  • 3
  • 8
  • 18
10
votes
3 answers

expected Hash (got Array) for param 'samples'

I have been following Railscasts episodes of Nested forms and complex forms. During the time of creating multiple model in a single form I was able to edit, update, delete and create records for sample models that were nested in the Batch model. I…
A1aks
  • 187
  • 2
  • 15
10
votes
1 answer

No association found for name - Nested Form Rails 4

I have problems with has_many / has_many relationship using nested form for the following case. I have articles and this can have many units (Kg, bags, etc). And through my form I need to record these data. So I decided to use nested-form with…
10
votes
1 answer

Rails 4: accepts_nested_attributes_for and mass assignment

I am trying to reproduce railscast #196 in Rails 4. However, I'm experiencing some problems. In my example I try to generate a Phonebook - each Person could have multiple PhoneNumbers These are important parts of my controller: class…
speendo
  • 11,483
  • 19
  • 66
  • 100
10
votes
1 answer

has_many nested form with a has_one nested form within it

I am currently trying to make a form for a model, which has a dynamic number of nested models. I'm using Nested Forms (as described in RailsCasts 197). To make things even more complicated, each of my nested models has a has_one association with a…
Bryan Ashley
  • 971
  • 7
  • 22
10
votes
2 answers

Adding dynamic fields to nested form through AJAX

I've been watching and reproducing these railscasts on my app: 196-nested-model-form-part-1 and 197-nested-model-form-part-2. I do not yet have a pro account so i can't watch the revised episode. I'm developing under rails4 (edge) and…
Crystark
  • 3,101
  • 3
  • 32
  • 51
9
votes
1 answer

Form with nested attributes with a has_one association not working in Rails 3

I'm tring to set values for two models that have a has_one association using accepts_nested_attributes_for, but nothing in the fields_for is being shown on the view. I have confirmed the same code works on Rails 2.x, and it works fine when its a…
Saifis
  • 1,981
  • 1
  • 19
  • 35
9
votes
1 answer

Default action performed by jQuery on the partial data in ruby on rails

I am attempting the following. A customer select option in the main form. when a user selects a customer in the main form his bills should appear in the all the subsequent partials. I am using ryan bates's nested_form gem to get the partial. the…
9
votes
2 answers

Rails nested_form adding items to table rows

My goal is to use the nested_form gem: https://github.com/ryanb/nested_form but instead of creating just a new set of labels and fields every time you add an object, I wanted to insert a row into an existing table. = nested_form_for @transaction…
kevinweaver
  • 513
  • 1
  • 4
  • 14
8
votes
3 answers

Rails forms for has_many through association with additional attributes?

How can I generate form fields for a has_many :through association that has additional attributes? The has_many :through relationship has an additional column called weight. Here's the migration file for the join table: create_table :users_widgets…
Marco
  • 4,174
  • 6
  • 40
  • 75
8
votes
1 answer

Is it possible to do deep nesting in active admin?

It's the third day I'm crushing on Active Admin. I have @survey that has_many :questions and each question has_many :answers - they are actually variants users can choose from. But still I cant put it to work, it just doesn't create anything deeper…
prikha
  • 1,783
  • 15
  • 26
8
votes
3 answers

rails simple_nested_form_for fields_for wrong number of arguments

So I'm building a form in rails 3.1, using <%= simple_nested_form_for(@person, :url => collection_url, :html=>{:multipart => true}) do |f| %> <%= render :partial => "form", :locals => { :f => f } %> <% end %> but this line in the partial is…
8
votes
1 answer

Rails nested form error, child must exist

I'm following the tutorial: http://www.amooma.de/screencasts/2015-01-22-nested_forms-rails-4.2/ I'm usign Rails 5.0.0.1 But when I register a hotel, it appears that the hotel category must exist. 1 error prohibited this hotel from being saved:…