Ok, correct me if I'm wrong, but it doesn't seem like you are actually saving the object anywhere. In your create and update actions, you call new and then do not save it.
To fix this, you can do:
def create params[:kid][:new_grandparent_attributes] ||= {} @kid = Kid.new(params[:kid]) if @kid.save # successful save logic here else #failed save logic here end end def update params[:kid][:existing_grandparent_attributes] ||= {} @kid = Kid.find(params[:id]) if @kid.update_attributes(params[:kid]) #successful save logic here else #failed save logic here end end
Then, in your selection field, you try to find each Entity entry, not the Entity fields that are associated with @kid. To do this, you will need to establish a relationship between the child and grandparents.
# CLASS GRANDPARENT class Grandparent < ActiveRecord::Base has_many :parents has_many :grand_kids, :through => :parents end # CLASS PARENT class Parent < ActiveRecord::Base belongs_to :grandparent, :class_name => "Grandparent", :foreign_key => "grandparent_id" has_many :kids end # CLASS KID class Kid < ActiveRecord::Base belongs_to :parent, :class_name => "Parent", :foreign_key => "parent_id" belongs_to :grandparent # ...
This way you can access your @kid.grandparents through @kid.grandparents . Then you can generate a selection box:
<%= g_f.collection_select(:name ,@kid.grandparents, :id, :name) %>
source share