Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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 4 表单中的Rails 4嵌套属性未保存_Ruby On Rails 4_Nested Forms - Fatal编程技术网

Ruby on rails 4 表单中的Rails 4嵌套属性未保存

Ruby on rails 4 表单中的Rails 4嵌套属性未保存,ruby-on-rails-4,nested-forms,Ruby On Rails 4,Nested Forms,我正在尝试在rails 4中构建一个嵌套表单。我已经启动并运行了视图,但是当我提交表单时,这些值不会保存到我的数据库中。我通读了下面的答案,并试图在代码中复制它,但仍然存在相同的问题: 以下是我认为相关的代码片段: 视图: 到期金额模型: class AmountDue < ActiveRecord::Base belongs_to :invoice belongs_to :user end class AmountDue

我正在尝试在rails 4中构建一个嵌套表单。我已经启动并运行了视图,但是当我提交表单时,这些值不会保存到我的数据库中。我通读了下面的答案,并试图在代码中复制它,但仍然存在相同的问题:

以下是我认为相关的代码片段:

视图:

到期金额模型:

class AmountDue < ActiveRecord::Base
 belongs_to :invoice
 belongs_to :user
end
class AmountDue
发票型号:

class Invoice < ActiveRecord::Base
 belongs_to :user
 validates :user_id, presence: true
 has_many :amount_dues
 accepts_nested_attributes_for :amount_dues
end
class发票
找到了答案。在我看来,我没有用复数:到期金额

class AmountDue < ActiveRecord::Base
 belongs_to :invoice
 belongs_to :user
end
class Invoice < ActiveRecord::Base
 belongs_to :user
 validates :user_id, presence: true
 has_many :amount_dues
 accepts_nested_attributes_for :amount_dues
end