I have a Rails app where I was doing a general delete dialog with "are you sure" before it gets deleted. That's all fine, but I also have a small ajax on click to remove the block containing all the information. The block gets removed no matter what which makes things confusing. I couldn't seem to find any documentation online on how to conditionally execute an action after the confirm symbol.
My code looked like this:
<%= link_to_remote "Delete", :url =>
{:controller => "pixel", :action => :destroy, :id => pixel.id},
:onclick=>"$(this).up(0).remove()" %>
Thanks!
I don't have time to pursue an example right now, but try using the
:complete
option tolink_to_remote
to remove the element after the action completes, instead of:onclick
.http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001645 - look at the "callbacks" section.
It's probably as simple as: