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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---