我有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个表。
我该怎么做?
答案 0 :(得分:0)
使用accepts_nested_attributes_for
。
http://robots.thoughtbot.com/post/52960938209/accepts-nested-attributes-for-with-has-many-through