# Inserting a form on a page when button pressed

**URL:** <https://www.ruby-forum.com/t/inserting-a-form-on-a-page-when-button-pressed/160352>\
**Category:** Rails\
**Created:** [February 15, 2009, 7:28am UTC](https://www.ruby-forum.com/t/inserting-a-form-on-a-page-when-button-pressed/160352 "2009-02-15T07:28:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scudco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@scudco](https://www.ruby-forum.com/u/scudco)\
**Post date:** [February 15, 2009, 7:28am UTC](https://www.ruby-forum.com/t/inserting-a-form-on-a-page-when-button-pressed/160352/1 "2009-02-15T07:28:04Z")

</div>

Ive googled this and searched here and other forums but not getting  
appropriate reuslts. Perhaps someone on the board can help.

All i want to do is to have a button/link on a page such as “add task”  
which when pressed will insert the appropriate form plus fields directly  
under the button/link. Im wondering do i use use remote\_link\_for for  
this and if it will link back to the current views controller right? or  
is there a simpler way of doing this.

IF on the same page i had varius links of this sort such as “add task”,  
“expand table”, “collapse table” and they all linked back to the same  
controller action, how would i diferentiate between them. Would the  
logic be in the controller opening up different rjs files or would it be  
in teh one rjs file?

Any help on any of the points would help me out a lot!

---

<div class="post-metadata">

**Author:** ![scudco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@scudco](https://www.ruby-forum.com/u/scudco)\
**Post date:** [February 15, 2009, 11:41am UTC](https://www.ruby-forum.com/t/inserting-a-form-on-a-page-when-button-pressed/160352/2 "2009-02-15T11:41:42Z")

</div>

the easiest way to add a form onClick is to include it in the original  
view. just use a div to wrap it and set its height to 0px and overflow  
to hide. now onClick of your button you could call a javascript to  
reset height. you could even add a nice morph-effect or something like  
it.

of course you could do the same with an AJAX-call to update the html  
of a formerly empty div. your attempt to use remote\_link\_to seems  
promising, too.

to which action in which controller you link is your decision and  
depends on the structure of your app.

unfortunately i can’t understand your last problem:

> IF on the same page i had varius links of this sort such as “add task”,  
> “expand table”, “collapse table” and they all linked back to the same  
> controller action, how would i diferentiate between them. Would the  
> logic be in the controller opening up different rjs files or would it be  
> in teh one rjs file?

different links to the same action? if they should do the same, why  
label them differently? if not, why use the same action. you could  
just add an action called “add\_task”, another called “expand\_table”  
and so on…

hope i could help you anyway.

---

<div class="post-metadata">

**Author:** ![scudco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@scudco](https://www.ruby-forum.com/u/scudco)\
**Post date:** [February 17, 2009, 2:15pm UTC](https://www.ruby-forum.com/t/inserting-a-form-on-a-page-when-button-pressed/160352/3 "2009-02-17T14:15:21Z")

</div>

many thanks mad for your explanation. Im going to use the ajax call  
method for now.
