# Can javascript handle 422 response

**URL:** <https://www.ruby-forum.com/t/can-javascript-handle-422-response/137219>\
**Category:** Rails\
**Created:** [May 10, 2008, 7:36am UTC](https://www.ruby-forum.com/t/can-javascript-handle-422-response/137219 "2008-05-10T07:36:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 10, 2008, 7:36am UTC](https://www.ruby-forum.com/t/can-javascript-handle-422-response/137219/1 "2008-05-10T07:36:34Z")

</div>

I’m toggling a check box via ajax using:

application\_helper.rb:  
…  
def toggle\_value(object)  
remote\_function(:url =\> url\_for(object),  
:method =\> :put,  
:before =\> “Element.show(‘spinner-  
#{object.id}’)”,  
:complete =\> “Element.hide(‘spinner-  
#{object.id}’)”,  
:with =\> “this.name + ‘=’ + this.checked” )  
end

some\_controller.rb:  
…  
@response = Response.find(params[:id])  
respond\_to do |format|  
if @response.update\_attributes(params[:response])  
flash[:notice] = ‘Response was successfully updated.’  
format.html { redirect\_to(@response) }  
format.xml { head :ok }  
format.js { head :ok }  
else  
format.html { render :action =\> “edit” }  
format.xml { render :xml =\> @response.errors, :status  
=\> :unprocessable\_entity }  
format.js { head :unprocessable\_entity }  
end  
end

some\_view.html.erb:  
…  
\<%= check\_box\_tag ‘response[status]’, “1” , response.status ==  
“done”, :onclick =\> toggle\_value(response) %\>  
\<%= image\_tag ‘spinner.gif’, :id =\> “spinner-#{response.id}”, :style  
=\> ‘display: none’ %\>

The problem is how do check for a 422 response (i.e. the  
unprocessable\_entity) and uncheck the check box ?  
Thanks for any help.  
chris
