Rails

时间:2016-06-22 14:23:33

标签: ruby-on-rails nested-forms has-many

我有两个名为Consumer and Complaint的模型如下:

class Complaint < ActiveRecord::Base
  belongs_to :consumer
end


class Consumer < ActiveRecord::Base
  has_many :complaints

  accepts_nested_attributes_for :complaints
end

使用nested_form我可以同时注册消费者和投诉,但我之前执行搜索以验证消费者已经注册。

如果确实如此,表单将从Consumer加载数据并加载之前为此Consumer注册的所有Complaints中的数据。

我只想从Consumer加载数据并且只有一个Complaint有空白字段,并且在提交表单时,如果需要更新Consumer,并保存新的Complaint(好像关联是has_one)。

我的英语不流利,所以我为任何错误道歉。

0 个答案:

没有答案
相关问题