views:

112

answers:

1

I'm using a javascript call to dynamically remove a field from a form. My problem is that the action happens very quickly, and it's not reversible. So I'd like to add the standard Rails delete confirmation, but I can't figure out how to make it work. Basically, I want to add this ... :confirm => ‘Are you sure?’

Here's the line of javascript responsible for removing the field:

<%= link_to_function “Remove”, ”$(this).up(’.task’).remove()” %>

This is from a standard implementation of the Ryan Bates multi-model form technique from Advanced Rails Recipes.

I can provide more details if needed. Thanks.

+1  A: 

I don't think the :confirm option is available on link_to_function is it?

Try adding it yourself:

<%= link_to_function "Remove",
        "if(confirm('Are you sure?')) $(this).up('.task').remove()" %>
Roatin Marth