ruby on rails 3 - Return error to ajax on action decision -


i have controller action looks -

    def upvote       @post = post.find(params[:id])       if user_has_rated_post?          # want interrupt ajax here          redirect_to[:forum, @post.question], :notice => "you voted post"       else         @post.upvote         add_rating_to_post(1, @post)         @post.save          redirect_to[:forum, @post.question], :notice => "post voted"       end     end 

and have ajax call vote post, works fine except need stop ajax call if first condition, user_has_rated_post? met.

so question how can interrupt or force error return ajax, or should trying go way?

yes have return jquery(or ajax solution) interprets error. have handle error in javascript code(or nothing if fits). think above 400 convention considered error. see list of http status codes , pick 1 suits http://www.w3.org/protocols/rfc2616/rfc2616-sec10.html. here bet on 403 - server understood request, refusing fulfill it. can render 500, think it's better specific.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -