2011-05-13 98 views
0

注册用户每个User只能有一个MedicalHistory所以我有从另一个模型

class User < ActiveRecord::Base 
    acts_as_authentic 
end 

class MedicalHistory < ActiveRecord::Base 
    belongs_to :user 
end 

使用上面我可以成功地创建从MedicalHistory模式在控制台的用户:

newuser = Medicalhistory.new 
newuser.user = User.new 
newuser.user.username='testusername' 
newuser.user.password='blahblah' 
newuser.user.password_confirmation='blahblah' 
newuser.user.save 

MedicalHistory面貌如下

#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%> 

错误

当提交我收到以下错误形式:

User(#-) expected, got ActiveSupport::HashWithIndifferentAccess(#) 

错误是以下行:

#controller 
def create 
    @medicalhistory = Medicalhistory.new(session[:medicalhistory_params]) #gives error 
    #somewhere here I should extract registration fields and register the user 
end 

问题 有没有一种方法可以让我避免领域在部分(注册字段)进入session[:medicalhistory_params] ...有没有except什么?

回答

0

有没有理由不在#create中使用类似params[:medical_history]的东西?

相关问题