Inserting a form on a page when button pressed


#1

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!


#2

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.


#3

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