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
17
votes
3 answers

Rails 4.0 with Devise. Nested attributes Unpermited parameters

I am working on a web-app using Devise and Rails 4. I have a User model which I have extended with 2 extra form fields such that when a user signs up he can also submit his first/last names. (based on…
16
votes
3 answers

Rails has_many through form with checkboxes and extra field in the join model

I'm trying to solve a pretty common (as I thought) task. There're three models: class Product < ActiveRecord::Base validates :name, presence: true has_many :categorizations has_many :categories, :through => :categorizations …
ok32
  • 1,301
  • 12
  • 26
16
votes
3 answers

What rules does HTML follow when constructing parameters?

I'm using Rails to auto-magically create child objects based on a complex set of nested attributes. Therefore, I need the parameters to be nested in a very particular way. Obviously I realize I can construct them however I want with JS, but I'd like…
james
  • 3,361
  • 5
  • 37
  • 83
16
votes
2 answers

Rails - User Input for Multiple models on a single form - How

This is basically a nested form question, albeit with only one field that belongs to a parent model. My data entry form collects data for a model - however I also need to collect one other a data element/value (UserID) that actually goes into a…
BrendanC
  • 463
  • 1
  • 6
  • 18
15
votes
4 answers

Rails: radio button selection for nested objects

I'm stuck with this simple selection task. I have this models: # id :integer(4) not null, primary key # category :string(255) # content :text class Question < ActiveRecord::Base has_many :choices, :dependent => :destroy …
15
votes
1 answer

nested form triggering a 'Can't mass-assign protected attributes warning

I've got a multi layer nested form User->Tasks->Prerequisites and in the same form User->Tasks->Location The location form works fine, now I'm trying to specify prerequisites to the current task. The prerequisite is a task_id stored in the…
pedalpete
  • 19,318
  • 41
  • 115
  • 225
15
votes
2 answers

accepts_nested_attributes_for to link to existing record, not create a new one

I have the following models class Order < AR::Base has_many :products accepts_nested_attributes_for :products end class Product < AR::Base belongs_to :order has_and_belongs_to_many :stores accepts_nested_attributes_for…
Manuel Meurer
  • 3,170
  • 6
  • 31
  • 50
15
votes
3 answers

Angular JS ngResource with nested resources

I'm trying out angular JS and I want to get data from a nested resource defined in my rails application. I wrote the following lines: UserMission = $resource("/users/:user_id/user_missions/:id", {user_id: "@user_id", id: "@id"}, {update: {method:…
GTDev
  • 5,258
  • 8
  • 45
  • 80
14
votes
1 answer

How does the HTML5 multiple file upload field map to a nested model in Rails 3?

I'm trying to use the HTML5 multiple attribute on a file field in a nested form. The models are as follows: class Album < ActiveRecord::Base has_many :album_images has_many :images, :through => :album_images accepts_nested_attributes_for…
cotopaxi
  • 827
  • 1
  • 11
  • 19
13
votes
1 answer

adding nested attributes with checkboxes in rails 4 using mass assignment

error: param is missing or the value is empty: color I am making a form where I can add nested attributes to a parent record and I want to add them through checkboxes. I have the parent model "Car" and the child model "Colors"…but I want to start…
NothingToSeeHere
  • 1,743
  • 3
  • 21
  • 49
13
votes
1 answer

Why do I get a AssociationTypeMismatch when creating my model object?

I get the following error: ActiveRecord::AssociationTypeMismatch in ContractsController#create ExchangeRate(#2183081860) expected, got HashWithIndifferentAccess(#2159586480) Params: {"commit"=>"Create", …
Maxm007
  • 1,148
  • 2
  • 13
  • 20
12
votes
2 answers

How to handle multiple models in one rails form?

I have the following models class Survey < ActiveRecord::Base has_many :survey_sections accepts_nested_attributes_for :survey_sections end class SurveySection < ActiveRecord::Base belongs_to :survey has_many :questions …
rob.d
  • 163
  • 1
  • 1
  • 7
12
votes
1 answer

How to access nested params

I would like to get some nested params. I have an Order that has many Items and these Items each have a Type. i would like to get the type_id parameter from the controllers create method. @order = Order.new(params[:order]) @order.items.each do |f| …
Flexo
  • 2,386
  • 3
  • 20
  • 32
12
votes
1 answer

nested_form/cocoon: is it okay to use table rows for nested fields?

I normally don't use tables for forms, but when having a nested form (when using nested_form or cocoon gem), is it okay then to put each set of form elements inside a table row? To me, this seems pretty intuitive: every row in the table represents…
Joshua Muheim
  • 10,965
  • 6
  • 61
  • 127
11
votes
3 answers

How to convert a MultiDict to nested dictionary

I would like to convert a POST from Webob MultiDict to nested dictionary. E.g. So from a POST of: 'name=Kyle&phone.number=1234&phone.type=home&phone.number=5678&phone.type=work' to a multidict; [('name', 'Kyle'), ('phone.number', '1234'),…
Kyle Finley
  • 11,202
  • 6
  • 39
  • 64