Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 从另一个模型注册用户_Ruby On Rails_Ruby On Rails 3_Activerecord - Fatal编程技术网

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