{"id":936,"date":"2022-08-30T15:09:39","date_gmt":"2022-08-30T15:09:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/problem-about-cocoon-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:09:39","modified_gmt":"2022-08-30T15:09:39","slug":"problem-about-cocoon-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-cocoon-collection-of-common-programming-errors\/","title":{"rendered":"problem about cocoon-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/74050cd0fb772cdacba70f80ead4405c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ndax<br \/>\nruby-on-rails-3 cocoon<br \/>\nEDIT &#8211; fixed: The problem was the params hash and after looking through a lot of questions on SO, i came up with the following solution, which (so far) works well:the student_groups#new action now looks like this &#8211; maybe there&#8217;s a better way to parse the params, but &#8230;this works! def create @student_group = @user.student_groups.build(params[:student_group]) ### http:\/\/stackoverflow.com\/questions\/2610263\/how-to-access-nested-params @params = params[:student_group][:students_attributes] if @student_group.save### http:\/\/stackoverflow.com\/questions\/14502508\/undefined-method-for-nilnilclass-when-pushing-values-to-an-array if @params.present?@params.values.each do |student|@student_group.students.create(name:&#8221;#{student[:name]}&#8221;, gender: &#8220;#{student[:gender]}&#8221;)endend # new subject pathredirect_to class_path(@student_group), flash: { success: &#8220;#{@student_group.name} has been added successfully&#8221; } else@title = &#8220;Create a new group&#8221;flash.now[:error] = &#8220;Something&#8217;s gone wrong. Please try again!&#8221;render &#8216;new&#8217; end endstudent_group.rb: I had to mark :_destroy as attr_accessorclass StudentGroup &lt; ActiveRecord::Base### https:\/\/github.com\/ryanb\/nested_form\/issues\/222attr_accessor :_destroyattr_accessible :name, :number_of_students, :type_of_group, :students_attributesbelongs_to :userhas_one :age, dependent: :destroyhas_many :students, dependent: :destroyaccepts_nested_attributes_for :students, :rejec<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/b9f81801b50ddbd023d2bf3ef5c03e91?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSteven<br \/>\ndevise ruby-on-rails-4 cocoon<br \/>\nIn Rails 4 I want to create an order including product in a devise seller, I use gem &#8220;cocoon&#8221;class Seller &lt; ActiveRecord::Base has_many :ordersclass Order &lt; ActiveRecord::Base belongs_to :seller has_many :products accepts_nested_attributes_for :products, allow_destroy: trueclass Product &lt; ActiveRecord::Base belongs_to :orderand I want to create in new.html but the seller don&#8217;t need to sign in, I hope it can via URLnew.html<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:00:50. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>dax ruby-on-rails-3 cocoon EDIT &#8211; fixed: The problem was the params hash and after looking through a lot of questions on SO, i came up with the following solution, which (so far) works well:the student_groups#new action now looks like this &#8211; maybe there&#8217;s a better way to parse the params, but &#8230;this works! def create [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-936","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=936"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/936\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}