Note that there are some explanatory texts on larger screens.

plurals
  1. POrails ajax update and list same page
    primarykey
    data
    text
    <p>my requirement: list and edit form on the same page <img src="https://i.stack.imgur.com/qRkmE.png" alt="enter image description here"></p> <p>whenever user clicks on 'Edit' button, form edit will be showed(default hide) and data in form will be filled with data from row that was clicked.After user edit name and click 'Save' button->row table will be update without refresh page.</p> <p>File index.html.haml</p> <pre><code>%label.lblCapTbl Client Organizations .edit_client_org #ShowHideForm %strong Edit Client Organization .client_orgs_edit_from = render :partial =&gt; 'edit' .wrapper-table %table#tbl-orgs.table.table-striped %thead %tr %th Client Organizations %th Client Account Directors %th %th %tbody = render @client_orgs </code></pre> <p>File _edit.html.haml</p> <pre><code>#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 =&gt; 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 =&gt; 'done',class:"btn" </code></pre> <p>File _client_org.html.haml</p> <pre><code>%tr{:id =&gt; "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 =&gt; true,class: 'btn link_edit_client_org' </code></pre> <p>When user presses 'Edit' button.File ClientOrgController</p> <pre><code>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 </code></pre> <p>ajax </p> <pre><code>$('.link_edit_client_org').on('ajax:success', function(evt, data, status, xhr){ $(".edit_client_org").show(); $('input[name="client_org[name]"]').val(data.name); }); </code></pre> <p><strong>My question</strong></p> <p>when I press 'Save' button on Edit form --> ajax call create action instead of update action inside ClientOrgController?.I found out that in form edit @client_org variable always nil because in edit function( in ClientOrgControler) I return json data which needed to fill in edit form.</p> <p>Anyone can help me? Thanks in advance </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload