【发布时间】:2012-02-16 05:10:45
【问题描述】:
当用户点击特定项目时,我使用jQuery's post method 更新数据库中的内容:
$.post("/posts/" + post_id + "/update_something",
{ some_param: some_value },
success_handler);
update_something 看起来像这样:
def update_something
post = Post.find(params[:id])
post.update_attributes(:some_field => params[:some_param])
render :nothing => true
end
问题是如果update_attributes失败,请求仍然成功,success_handler被执行。
当update_attributes 失败以致success_handler 不会被执行时,如何导致请求失败?
【问题讨论】:
标签: jquery ruby-on-rails ajax ruby-on-rails-3 jquery-post