Note that there are some explanatory texts on larger screens.

plurals
  1. PORails ajax update
    primarykey
    data
    text
    <p>I would like to change a Workorder.wostatus_id based on data in html.</p> <p>In my index html, I have the wostatus.id stored like this:</p> <pre><code>&lt;span id="woid"&gt;4&lt;/span&gt; </code></pre> <p>I would like to update the workorder.wostatus_id = 4 </p> <p>This is in the workorders.js.coffee - but, it's not working:</p> <pre><code> $.ajax type: 'POST' url: 'http://localhost:5000/workorders' data: workorder: wostatus_id: $("#woid").val() </code></pre> <p>Maybe I'm not getting to the right workorder record?</p> <p>Even doing this didn't update the workorder.wostatus_id</p> <pre><code> $.ajax type: 'POST' url: "http://localhost:5000/workorders" data: workorder: wostatus_id: '3' </code></pre> <p>This didn't work either:</p> <pre><code> $.ajax type: 'POST' url: "http://localhost:5000/workorder/17" data: wostatus_id: '7' </code></pre> <p>I'm missing something big time.</p> <p>Does the ajax POST execute this code in the workorder controller????</p> <pre><code> # PUT /workorders/1 # PUT /workorders/1.json def update @workorder = Workorder.find(params[:id]) respond_to do |format| if @workorder.update_attributes(params[:workorder]) format.html { redirect_to @workorder, notice: 'Workorder was successfully updated.' } format.json { head :ok } else format.html { render action: "edit" } format.json { render json: @workorder.errors, status: :unprocessable_entity } end end </code></pre> <p>UPDATE:</p> <p>I added this to the workorder controller:</p> <pre><code> def changestatus @workorder = Workorder.find(params[:id]) @workorder.update_attribute :wostatus_id, '4' render nothing: true end </code></pre> <p>I added this to the routes:</p> <pre><code> resources :workorders do member { put :changestatus } end </code></pre> <p>This is currently in the js.coffee:</p> <pre><code> $.ajax type: 'PUT' url: "http://localhost:5000/workorders/11/changestatus" data: wostatus_id: 4 </code></pre> <p>(I'm hard coding things until I get the next step working.)</p> <p>SO - this works, workorder 11 gets wostatus_id changed to 4.</p> <p>But, now I'm having trouble getting the right information from the html. The html contains 2 data fields I need - one for which workorder and the other is what the wostatus_id is.</p> <p>Here is the html for the update url:</p> <pre><code>&lt;div class="false" data-change-url="http://localhost:5000/workorders/16/changestatus"&gt; </code></pre> <p>I thought this would get that url - but, it doesn't work:</p> <pre><code>$(this).data('change-url') </code></pre>
    singulars
    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