I am having problems adding children to this parent. The view has a “Add Child” link, which runs in the current Person object. I'm stuck from here. Both the parent and the child are Person objects.
In addition, the logic is bad - she is currently accepting a father.
Model (person.rb):
class Person < ActiveRecord::Base has_many :children, :class_name => "Person" belongs_to :father, :class_name => "Person", :foreign_key => 'father_id' belongs_to :mother, :class_name => "Person", :foreign_key => 'mother_id' def children Person.find(:all, :conditions => ['father_id=? or mother_id=?', id, id]) end end
Controller (people_controller.rb):
class PeopleController < ApplicationController
View (people / _form.html.erb):
<%= link_to "Add Child", {:controller => '/people', :action => :new, :parent_id => @person.id} %>
source share