1

i'm using ruby on rails in my backend and angularjs in my client side.

here's a scenario i input same email in my form so in my console response a 422 (Unprocessable Entity) and said 'email was use'. it means my validation was good and working properly in my backend.

my question is how can u get that response and put that in my view so user can see that email was already in use.

1 Answer 1

1

If you are using angular's $http service, getting the status code of the response is simple, just access res.status from one of your factories/services:

$http.get(`/route/${id}/foo.json`).then(function(res){
    callback(res)
}).catch( (error) => { console.log(error) })

If you want to get that into a controller, I suggest using a callback function like this:

someFactory.get($scope.id, function(data){
    console.log("data.status");
})
Sign up to request clarification or add additional context in comments.

1 Comment

yeah whichever route you have set up in your backend... Hope it worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.