problem about cocoon-Collection of common programming errors

  • dax
    ruby-on-rails-3 cocoon
    EDIT – 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 – maybe there’s a better way to parse the params, but …this works! def create @student_group =[:student_group]) ### @params = params[:student_group][:students_attributes] if if @[email protected] do |student|@student_group.students.create(name:”#{student[:name]}”, gender: “#{student[:gender]}”)endend # new subject pathredirect_to class_path(@student_group), flash: { success: “#{} has been added successfully” } else@title = “Create a new group”[:error] = “Something’s gone wrong. Please try again!”render ‘new’ end endstudent_group.rb: I had to mark :_destroy as attr_accessorclass StudentGroup < ActiveRecord::Base### :_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

  • Steven
    devise ruby-on-rails-4 cocoon
    In Rails 4 I want to create an order including product in a devise seller, I use gem “cocoon”class Seller < ActiveRecord::Base has_many :ordersclass Order < ActiveRecord::Base belongs_to :seller has_many :products accepts_nested_attributes_for :products, allow_destroy: trueclass Product < ActiveRecord::Base belongs_to :orderand I want to create in new.html but the seller don’t need to sign in, I hope it can via URLnew.html

Originally posted 2013-11-09 23:00:50.