Ruby on rails 从另一个模型注册用户
每个Ruby on rails 从另一个模型注册用户,ruby-on-rails,ruby-on-rails-3,activerecord,Ruby On Rails,Ruby On Rails 3,Activerecord,每个用户只能有一个医疗历史,所以我有 class User < ActiveRecord::Base acts_as_authentic end class MedicalHistory < ActiveRecord::Base belongs_to :user end 医疗历史方面如下 #controller def new @medicalhistory = MedicalHistory.new @medicalhistory.user = U
用户
只能有一个医疗历史
,所以我有
class User < ActiveRecord::Base
acts_as_authentic
end
class MedicalHistory < ActiveRecord::Base
belongs_to :user
end
医疗历史方面如下
#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%>
错误位于以下行:
#controller
def create
@medicalhistory = Medicalhistory.new(session[:medicalhistory_params]) #gives error
#somewhere here I should extract registration fields and register the user
end
问题
是否有一种方法可以避免部分(注册字段)中的字段进入
会话[:medicalhistory_params]
…除了或其他什么之外,还有吗?在\create
中不使用类似参数[:medical_history]
的内容有什么原因吗?请按如下方式更改您的模型:
class MedicalHistory < ActiveRecord::Base
belongs_to :user
accepts_nested_attributes_for :user
end
class MedicalHistory
请参阅此处:您可能需要查看
请看这个介绍
#controller
def create
@medicalhistory = Medicalhistory.new(session[:medicalhistory_params]) #gives error
#somewhere here I should extract registration fields and register the user
end
class MedicalHistory < ActiveRecord::Base
belongs_to :user
accepts_nested_attributes_for :user
end