When user clicks a specific item, I use jQuery's post method to update something in the database:
$.post("/posts/" + post_id + "/update_something",
{ some_param: some_value },
success_handler);
where update_something
looks like this:
def update_something
post = Post.find(params[:id])
post.update_attributes(:some_field => params[:some_param])
render :nothing => true
end
The problem is if update_attributes
fails, the request still succeeds and success_handler
is executed.
How could I cause the request to fail when update_attributes
fails such that success_handler
won't be executed?