Rails从单一形式保存数据关联模型

时间:2013-10-23 02:18:06

标签: ruby-on-rails model model-associations

我有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个表。

我该怎么做?

1 个答案:

答案 0 :(得分:0)