0

我的要求:在同一页面上列出和编辑表单 在此处输入图像描述

每当用户单击“编辑”按钮时,将显示表单编辑(默认隐藏)并且表单中的数据将填充来自单击的行的数据。用户编辑名称并单击“保存”按钮后 - >行表将被更新没有刷新页面。

文件 index.html.haml

%label.lblCapTbl Client Organizations
  .edit_client_org
    #ShowHideForm
      %strong Edit Client Organization
      .client_orgs_edit_from
        = render :partial => 'edit'
.wrapper-table
  %table#tbl-orgs.table.table-striped
    %thead
      %tr
        %th Client Organizations
        %th Client Account Directors
        %th
        %th
      %tbody
        = render @client_orgs

文件 _edit.html.haml

#form_edit_client_org.formEditShow
  = form_for(@client_org,remote: true) do |f|
    #error_explanation
    .form_edit_org
      =f.label :"Name of Client Organization"
      =f.text_field :name ,:autofocus => true ,class: "input_name",placeholder: "Name"
     %br
      =f.label :"Client Account Director(email address)"
     %ul
    .btn_form_add
      = button_tag "Cancel", type: :button, id: "cancelForm", class: "btn"
      = f.submit "Save", :name => 'done',class:"btn"

文件 _client_org.html.haml

%tr{:id => "client_org_#{client_org.id}"}
  %td= client_org.name
  %td
    = client_org.users.first.email
  %td
    = link_to "Edit", edit_org_path(client_org), :remote => true,class: 'btn link_edit_client_org'

当用户按下“编辑”按钮时。文件 ClientOrgController

def edit
 @client_org = ClientOrg.find(params[:id])
 respond_to do |format|
   format.json { render json: @client_org, status: :created }
 end
end

def update
  //TODO
end

阿贾克斯

$('.link_edit_client_org').on('ajax:success', function(evt, data, status, xhr){
    $(".edit_client_org").show();
    $('input[name="client_org[name]"]').val(data.name);

});

我的问题

当我在编辑表单上按“保存”按钮时-> ajax 调用创建操作而不是 ClientOrgController 中的更新操作?我发现在表单中编辑 @client_org 变量总是为零,因为在编辑函数中(在 ClientOrgControler 中)我返回 json 数据需要填写编辑表格。

任何人都可以帮助我吗?提前致谢

4

0 回答 0