Episode #071 - Nested Forms with Cocoon

Drifting Ruby · 12K views · 2017 · 4:46

Open on YouTube

Web developmentPython, Ruby & scripting languagestutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about nested forms and accepts_nested_attributes_for in Rails, as a concrete walkthrough of the Cocoon gem.

Recommended by 4 people across 4 different months, 2017 to 2020.

What it is

A short Drifting Ruby screencast showing how to build a single Rails form that edits multiple models, using accepts_nested_attributes_for and the Cocoon gem to add and remove nested records without obtrusive JavaScript. It is presented by the Drifting Ruby channel and runs under five minutes.

What people said

Recommends mayorsanmayor · 2017-03 · Stack Overflow · on “Nested form isn't saved”

I used this tutorial to implement nested forms with cocoon gem just few hours ago. You might find it useful. [this video] To get a strong understanding of how to create a nested form you should also see this video on how to do it without a gem. [LINK]

Recommends Muhammad Ibraheem · 2017-12 · Stack Overflow · on “Proper model set up”

If you want to create nested models on the same page. i.e. milages within trip page using accepts_nested_attributes_for, You can use cocoon gem. [LINK] Drifting Ruby has a video that shows the process in detail that is easy to follow. [this video] You can do it manually as well but it will require a little bit more work. With cocoon you will do have a Driver Controller and Trip controller but you don't need a Milage controller since it is handled with nested_attributes via Trip Controller. If you want to do it manually, you will need a bit of JavaScript. You can follow Ryan Bates RailsCast on this topic. railscasts.com/episodes/196-nested-model-form-revised

Recommends jane mason · 2018-10 · Stack Overflow · on “Create and sort questions in rails 5”

I am working on a survey app in which the user can create questions, but I want them to also sort the question in the same view. To accomplish the questions feature I'm using the same procedures like in "Drifting Ruby" video: [this video] Here is the code of my NEW view <%= simple_form_for @project do |f|%> <table summary='Project form fields'> <tr> <th>Name : </th> <td><%= f.input_field(:name)%></td> </tr> </table> <div id='questions' class='list-group' data-url="sort_path"> <%= f.simple_fields_for :questions do |question| %> <%= question.input :title%> <%= question.input :field_type%> <% end %> <div class='links'> <%= link_to_add_association 'Add question', f, :questions, class: "btn btn-outlin

Recommends Bondhan Sarker · 2020-06 · Stack Overflow · on “Triple Nested Attribute Forms in Rails”

In parent model: class Group < ActiveRecord::Base belongs_to :add_on_slider has_many :classifications, dependent: :destroy accepts_nested_attributes_for :classifications, allow_destroy: true, :reject_if => :all_blank end In parent controller : def grouo_params params.require(:group).permit(:attribute name1, :attribute name2, :sub_title, classifications_attributes: [:id, :main_point, :_destroy, :important_id ,items_attributes: [:id, :attribute, :_destroy, :important_id]]) end In the view page: You can use gem 'cocon'. You can see any tutorial related to it. [this video]