Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.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 如何使嵌套的_属性在Rails3中工作?_Ruby On Rails_Forms_Ruby On Rails 3_Nested Attributes - Fatal编程技术网

Ruby on rails 如何使嵌套的_属性在Rails3中工作?

Ruby on rails 如何使嵌套的_属性在Rails3中工作?,ruby-on-rails,forms,ruby-on-rails-3,nested-attributes,Ruby On Rails,Forms,Ruby On Rails 3,Nested Attributes,以下是我的用户模型: class User < ActiveRecord::Base has_one :teacher, :dependent => :destroy accepts_nested_attributes_for :teacher, :allow_destroy => true attr_accessible :email, :password, :password_confirmation, :remember_me, :teacher_attrib

以下是我的用户模型:

class User < ActiveRecord::Base
  has_one :teacher, :dependent => :destroy
  accepts_nested_attributes_for :teacher, :allow_destroy => true
  attr_accessible :email, :password, :password_confirmation, :remember_me, :teacher_attributes
end
我不知道它是否相关,但表单没有在教师属性数组或任何东西中生成字段——它在教师内部。我猜这就是我的问题所在,但我不知道如何让它,把字段放在里面。请帮忙

谢谢

试试这些东西:

在视图顶部:

<% @user.build_teacher if @user.teacher.nil? %>

对于以下字段:

<%= user.fields_for :teacher do |t| %>


另外,就我个人而言,我喜欢将表单中的块参数命名为
| user |
|t |
)(因为当你在漫长的一天中看到视图中的
user
而不是
表单
,这会让你感到困惑!)

我爱你。我现在真的在流泪。为什么这句话花了我4个小时的生命?为什么?有时候你需要第二双眼睛,结果证明这是一个非常简单的问题。我也遇到过同样的情况,我意识到如果你退后一步,做些别的事情,然后再回到问题上来,目的是分析而不是到处乱摸,那么它会有很大的帮助!当然,没有什么能比得上几本关于Rails的好书。我所需要的只是一些睡眠,然后事情开始进展得更快。谢谢你的回答和建议。
WARNING: Can't mass-assign protected attributes: teacher
<% @user.build_teacher if @user.teacher.nil? %>
<%= user.fields_for :teacher do |t| %>