[jifty-devel] Action in a link? Without a <form>?

Henry Baragar Henry.Baragar at instantiated.ca
Mon Feb 26 15:44:03 EST 2007

On Monday, February 26 2007 03:00 pm, jpollack at gmail.com wrote:
> Hi all,
> I'd like to be able to click on a link, and have that cause an action
> (with arguments) to be run, while remaining on the current page.  Does
> anyone know how I can do this?
The following might not be a perfect fit, but it meets our needs:

In the "original_page" template:

<% Jifty->web->link(
            label => 'Take action',
            url => "/take_acktion/arg1/arg2/arg3",
            onclick => {confirm => "Confirm taking of action"}

In Dispatcher.pm:

on qr{^/take_action/(\w+)/(\w+)/(\w+)$/}, run {
    my ($arg1, $arg2, $arg3) = ($1, $2, $3); 
    take_action($arg1, $arg2, $arg3);
    redirect "/original_page";

Note that this creates a confirmation pop-up (which we like because we believe 
that a link should not have side effects).  Also, I was not sure if you were 
referring to Jifty actions (not used here) or using a more generic 
definition, when you mentioned "actions".

Also note that the code has been changed to protect our customer and is not 
guaranteed to work (although the original source does work).

My question is:  is there a better way to do this?


> If you set submit => $action when making the J:W:Form:Clickable (as
> the documentation suggests), but don't need an enclosing <form>
> (because all arguments were specified during construction of the
> action), then I've found the rendered link fails to do anything
> useful.  Both as_link and as_button, clicking it results in nothing.
> I've hacked together something crude where I tangent to a page which
> contains $a = new_action; $a->run; jifty->web->return, which works,
> but causes the whole page to reload, which destroys any state I have
> in my regions.  Besides, it's ugly.
> Someone on IRC suggested months ago that I try to do something
> involving putting the action in a request or continuation, and then
> making the link call that.  Can anyone offer any ideas or suggestions
> on how to do this?  I've tried several things with continuations
> (putting the action in a request in the continuation, putting the
> action generation and execution in the 'code' block) all to no
> success.
> Should someone show me how to do this, I'd be happy to write
> documentation for it. ; )
> Thanks,
> Joshua
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel

More information about the jifty-devel mailing list