註冊用戶每個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
什麼?