ruby on rails - Return error as a JSON response -


the question simple: return error controller json response:

//controller def action1    # .....    return render(json: { status: :unprocessable_entity }) if !is_my_valid?    # .... doing    render(json: my_hash.to_json)    end 
//view $.ajax({   url: 'some_url',   //... }).done(function(data) {   // gets here in case of error  }).fail(function(jqxhr, textstatus) {   alert("error: " + textstatus); }); 

so problem on html page, in case of error, callback function in .done() executed, not 1 in .fail(). how make .fail()?

send 500 http status code:

render(json: { ... }, status: 500)   

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -