i want to implement a digg-like vote up/down method in my rails application using ajax. and i found that link_to_remote can do just that. but i want to check whether there's already a vote by the current user so that no user can vote up twice or more. how can i do that - how can i return values based on some condition so that an forbidden vote action triggers link_to_remote :failure condition??
+3
A:
You need to set the HTTP status code appropriately (not in the 200 range, you probably want 403 (forbidden, http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) unless you handle that separately in your app -- it doesn't really matter what the code is, just that it's not in 200 range).
To set the status code, in your render line, you add
:status => 403
It seems like you are all set for the rest of this (i.e., specifying and implementing the failure condition, etc. etc.)
Jason Yanowitz
2009-12-19 13:06:35