each User can only have one MedicalHistory so I have
class User < ActiveRecord::Base
acts_as_authentic
end
class MedicalHistory < ActiveRecord::Base
belongs_to :user
end
Using the above I can successfully create the user from the MedicalHistory model in the console:
newuser = Medicalhistory.new
newuser.user = User.new
newuser.user.username='testusername'
newuser.user.password='blahblah'
newuser.user.password_confirmation='blahblah'
newuser.user.save
MedicalHistory Side looks like following
#controller
def new
@medicalhistory = MedicalHistory.new
@medicalhistory.user = User.new
end
#form
<%=...%>
<%=f.intput :cell_phone%>
<%=f.fields_for :user do |builder|%>
<%= render "registration_form", :f => builder %>
<% end %>
#Partial
<%=f.input :email%>
<%=f.input :password%>
<%=f.input :password_confirmation%>
Error
When submitting the form I am getting below error:
User(#-) expected, got ActiveSupport::HashWithIndifferentAccess(#)
Error is on following line:
#controller
def create
@medicalhistory = Medicalhistory.new(session[:medicalhistory_params]) #gives error
#somewhere here I should extract registration fields and register the user
end
Question
Is there a way I can avoid fields in the partial (registration fields) getting into the session[:medicalhistory_params]…is there a except or something?
change your model as follows:
Ref here: http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html