[Catalyst] GET vs POST (was: Dispatching question)

Bill Moseley moseley at hank.org
Mon Nov 14 14:55:59 CET 2005


On Mon, Nov 14, 2005 at 02:28:41PM +0100, Johan Lindstrom wrote:
> At 14:09 2005-11-14, Bill Moseley wrote:
> >Then in your templates use the new uri_for method:
> >
> >    <a href="[% c.uri_for('edit') %]">Edit this item</a>
> >    <a href="[% c.uri_for('delete') %]">Delete this item</a>
> 
> Excellent to have a helper function for this! Me like mucho.
> 
> But isn't this (using GET requests for destructive actions) the same issue 
> that the Rails guys encountered with the Google Web Accelerator and the 
> shit storm that ended up with?


I do something like this in my delete actions:

sub delete : Local {
    my ( $self, $c, $id, $delete ) = @_;

    return $c->internal_redirect('list', { message => 'Invalid Item Selected' } )
        unless my $item = DB::Item->retrieve( $id );


    unless ( $delete && $c->req->method eq 'POST' ) {
        $c->stash->{template} = 'verify_delete.xhtml';
        $c->stash->{item} = $item;
        return;
    }

    if ( $c->req->parameters->{yes} ) {
        $c->stash->{message} = 'Deleted [' . $item->name . ']';
        $item->delete;
    }

    return $c->internal_redirect('list');
}

-- 
Bill Moseley
moseley at hank.org




More information about the Catalyst mailing list