I have a little ajax call that calls rails:
$.ajax({
type: "POST",
url: '...',
data: ({ ...
}),
success: function(response, status) {
console.log(status);
}
});
In the rails controller I'm simply deleting an entry from the database, and I simply want to return if it was successful or not. What's the best way?
Should I just return JSON in respond_to? If so, what exactly would you have it contain?
Best way to signify success in this way is to put the following in your controller...
def destroy
# ... your code ...
respond_to do |format|
format.json { head :ok }
end
end
try this it's working for me
def destroy
...
render json: {}, status: 200
end
I found this shorter way to do the job:
def destroy
# ... your code ...
head :ok # this will return HTTP 200 OK to jQuery!
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With