Skip to content

Instantly share code, notes, and snippets.

@i0n
Created October 31, 2010 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i0n/656237 to your computer and use it in GitHub Desktop.
Save i0n/656237 to your computer and use it in GitHub Desktop.
undefined method `id_criteria' for Array when submitting Rails 3 form containing more than one instance of a relationally associated mongoid document
class Person
include Mongoid::Document
include Mongoid::Timestamps
field :name, :type => String
key :name
references_many :books, :dependent => :destroy
accepts_nested_attributes_for :books
end
class Book
include Mongoid::Document
include Mongoid::Timestamps
field :title, :type => String
referenced_in :person
end
class PeopleController < ApplicationController
def new
@person = Person.new
2.times do
@person.books << Book.new
end
end
def create
@person = Person.new(params[:person])
respond_to do |format|
if @person.save
redirect_to @person, :notice => 'Saved.'
else
render :action => "new"
end
end
end
end
= form_for @person do |f|
.field
= f.label :name
= f.text_field :name
= f.fields_for :books do |f|
.field
= f.text_area :title
.actions
= f.submit 'Save'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment