jquery - Success/Fail in AJAX response from Rails -


i have following controller method:

def update     approval = approval.where(user: current_user, id: params[:id])     if approval.update_attributes(approved: params[:approved)         #success     else        #fail     end     respond_to |format|       format.js { render :nothing => true }     end end 

how manage send success or fail rails ajax call?

on rails part, can so:

def update     approval = approval.where(user: current_user, id: params[:id])     if approval.update_attributes(approved: params[:approved])        render nothing: true, status: ok     else       render nothing: true, status:      end end 

on json part, mentioned here:

$.ajax(serverurl, {    statuscode: {       200: function (response) {         // whatever       },       500: function (response) {         // whatever       }    } }); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -