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