I have 3 models . Doctor, Patient and User
with following associations

class Doctor < ActiveRecord::Base
        has_many :patients, :dependent => :destroy
        has_one :user, :as => :userable
        accepts_nested_attributes_for :user
end

class Patient < ActiveRecord::Base
        belongs_to :doctor
        has_one :user, :as => :userable
        accepts_nested_attributes_for :user
end

class User < ActiveRecord::Base
        belongs_to :userable, :polymorphic => true
end

I have a nested form for doctor and user as
OUTER FORM for :doctor
  INNER FORM for :user
  end
end

and in my users controller i have a create action as

  def create
        doc_attr = params[:doctor]
        user_attr = doc_attr.delete(:user)
        doctor = Doctor.new(doc_attr)
        doctor.save!
        doctor.user.create(user_attr) ### getting error on this
        ....................
  end

When i submit the form i get the error saying undefined method create
for nil:NilClass
I know this is relatively simple. Any help will be greatly
appreciated. Thanks in advance !!!

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to