-1

我有 3 张桌子

User(id,email)
Client_Org(id,name)
Role(id,user_id,client_org_id,role) role:default "CD"

表格添加新的客户组织

= form_for(@client_org,remote: true) do |f|
   .post_errors
   .form_add_email
     =f.label :"Name of Client Organization"
     =f.text_field :name ,:autofocus => true ,class: "input_name",placeholder: "Name"
     %br
     =f.fields_for(:user) do |uf|
       =uf.label :email
       =uf.text_field :email,:autofocus => true ,class: "input_email"
     .btn_form_add
       = button_tag "Cancel", type: :button, id: "cancelForm", class: "btn"
       = f.submit "Add Another Organization", :name => "add_another_org"
       = f.submit "Done", :name => 'done'

提交表单时的参数:client_org[name],client_org[user][email]

当管理员在上面提交表单时。我想将数据保存到 3 个表中。

我该怎么做?

4

1 回答 1

0

使用accepts_nested_attributes_for.

http://robots.thoughtbot.com/post/52960938209/accepts-nested-attributes-for-with-has-many-through

于 2013-10-23T02:30:56.577 回答