# Remote form with cancel

**URL:** <https://www.ruby-forum.com/t/remote-form-with-cancel/135186>\
**Category:** Rails\
**Created:** [April 18, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/remote-form-with-cancel/135186 "2008-04-18T23:13:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![apswartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@apswartz](https://www.ruby-forum.com/u/apswartz)\
**Post date:** [April 18, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/remote-form-with-cancel/135186/1 "2008-04-18T23:13:26Z")

</div>

I want an AJAX form to become part of the page when an item is clicked  
(I have this part working.)

However, I am stumped at what should be really easy. I want my form  
to have a “save” and a “cancel” button.

I have the “save” button working just fine.

The “cancel” basically calls a “cancel” action that replaces the AJAX  
form with what was there. (or at least that is what it does in my  
head.)

Do I have to create a second form that only has the cancel button in  
it? Or do I need to style both buttons as links? Or is there a  
better way?

Thanks in advance,

Alan

---

<div class="post-metadata">

**Author:** ![apswartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@apswartz](https://www.ruby-forum.com/u/apswartz)\
**Post date:** [April 19, 2008, 3:22am UTC](https://www.ruby-forum.com/t/remote-form-with-cancel/135186/2 "2008-04-19T03:22:34Z")

</div>

Depending on what you want it to look like you can use either

link\_to\_remote ‘text to display’, :url=\>…

or

button\_to\_function ‘button  
text’, :function=\>remote\_function(:url=\>…)

In either case, the url refers to the action that will render your  
original block are remove the form.

---

<div class="post-metadata">

**Author:** ![apswartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@apswartz](https://www.ruby-forum.com/u/apswartz)\
**Post date:** [April 24, 2008, 8:18pm UTC](https://www.ruby-forum.com/t/remote-form-with-cancel/135186/3 "2008-04-24T20:18:37Z")

</div>

This is probably obvious to everyone else, but I found what I thought  
was a VERY elegant solution to this problem:

\> stuff I wanted to go away here...

\<input type=“button” value=“Cancel” \<%= “onclick=$('item:” +  
@item.id.to\_s + “’).remove();” %\>\>

I am hope this is helpful to someone else…

–Alan
