[Catalyst] Can't seem to use forward or detach. Any special requirements?

kakimoto at tpg.com.au kakimoto at tpg.com.au
Sat Apr 25 14:55:30 GMT 2009


hello, all,

 I have a method in my controller which adds entries.

 The method is setup to match the path of 'users/subscriptions/add'.

 Upon successfully adding entries, I want the same method to be executed
again (only that the method will know which template (view) to call. I
tried using a detach (and even a forward) and I keep getting an error of
, 'Couldn't forward to command "/users/subscriptions/add": Invalid
action or component.'

 I have read the following page and a few others:
http://search.cpan.org/~hkclark/Catalyst-Manual-5.7020/lib/Catalyst/Manual/Intro.pod#Flow_Control

What am I doing wrong here? The request worked the first time round (ie
when creating a new entry).


URL: http://my-example.com/users/subscriptions/add

Reason why I am issuing a detach - To prohibit users from pressing
"Refresh" on the browser which will cause the application to readd the
entry again into the database (this happens because I suspect that the
request object is not flushed. I could easily kill off the parameters in
the request object but I figured I use a detach and have another (view)
template show up.


 Here's the code extract:

------------- Controller code extract - start ------------------------
sub create : Path('/users/subscriptions/add')
{
    my ($self, $c) = @_;
    my $template = q{agents/subscriptions/create.tt2};
    
    # Form is submitted using POST method.
    if ( $c->request->method eq 'POST')
    {       
         if (    
            $self->_process_entries(
                $c, 
                {   
                    'action'        => 'add',
                    'template'      => $template,
                    'target_action' =>
$c->uri_for('/users/subscriptions/add'),
                },
            )
        )   
        {   
            $c->log->debug(q{   Entry processed.});
            $c->detach(q{/users/subscriptions/add});
        }
    }   
    else    
    {
       # This one's to display an empty form.   
        ...
    }
    $c->{'stash'}->{'template'} = $template;

    return 1;
}


------------- Controller code extract - end  ------------------------


Thank you.

K. akimoto




More information about the Catalyst mailing list