When user clicks a specific item, I use jQuery\'s post method to update something in the database:
$.post(\"/posts/\" + post_id + \"/update_something\",
Well, you have to add an error handler, and give it an error to handle. So, in your JavaScript:
$.post( "/posts/" + post_id + "/update_something",
{ some_param : some_value }
)
.done( successHandler )
.fail( errorHandler ) // define errorHandler somewhere, obviously
;
And in Rails:
def update_something
post = Post.find params[ :id ]
success = post.update_attributes :some_field => params[ :some_param ]
head success ? :ok : :internal_server_error
end
Note: 500
may or may not be the appropriate error code here—choose whichever among the 400s and 500s is appropriate.