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 = @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 @[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: “#{@student_group.name} has been added successfully” } else@title = “Create a new group”flash.now[: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### 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
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.