how to use redirect_to

13 views
Skip to first unread message

aks...@gmail.com

unread,
May 6, 2019, 12:21:44 PM5/6/19
to Perl Kelp
Hi!
Try to use redirect_to from Kelp::Response like this:

sub build {
    my $self = shift;
    my $r = $self->routes;
    $r->add( '/',  { to => 'page', bridge => 1 } );
}

sub page {
    my ($self, $message) = @_;
    
    my %hash;
    if( $message ) {
        $hash{'message'} = $message;
    }

    $self->res->template( 'page.tt', \%hash );
}

sub strange_manipulations {
    my $self = shift;
    ...
    my $message;
    $message = "wow! wow! easy there!" if(something_happened);
    $self->res->redirect_to( '/', { 'message' => $message } );
}

but in page() $message alwais 'undef'. i think I am very wrong.
pls tell me how you can pass an attribute when using?
thanks!

vfil...@gmail.com

unread,
May 6, 2019, 12:55:50 PM5/6/19
to Perl Kelp
Did you try to get the message as a param?
sub page {
    my ($self) = @_;
    my $message = $self->param('message');

    my %hash;
    if( $message ) {
        $hash{'message'} = $message;
    }

    $self->res->template( 'page.tt', \%hash );
}

aks...@gmail.com

unread,
May 6, 2019, 1:02:39 PM5/6/19
to Perl Kelp

yes
понедельник, 6 мая 2019 г., 19:55:50 UTC+3 пользователь vfil...@gmail.com написал:

Valeriy Filatov

unread,
May 6, 2019, 3:17:20 PM5/6/19
to perl...@googlegroups.com
this one works.
Not sure if that is what you need...

sub build {

    my $self = shift;

    my $r = $self->routes;

    $r->add( '/',  'page' );

    $r->add( '/strange', 'strange_manipulations' );

}


sub page {

    my ($self) = @_;

    my $message = $self->param('message');


    my %hash;

    if( $message ) {

        $hash{'message'} = $message;

    }


    $self->res->template( 'page.tt', \%hash );

}


sub strange_manipulations {

    my $self = shift;

    my $message = "wow! wow! easy there!";

    $self->res->redirect_to( '/?message=' . $message );

}

Message has been deleted

aks...@gmail.com

unread,
May 7, 2019, 4:30:40 AM5/7/19
to Perl Kelp
Not exactly what I need, the link below has such information:

https://metacpan.org/pod/Kelp::Response#redirect_to
redirect_to

Redirects the client to a named route or to a given url. In case the route is passed by name, a hash reference with the needed arguments can be passed after the route's name. As a third optional argument, you can enter the desired response code:

$self->redirect_to( 'catalogue', { id => 243 });

понедельник, 6 мая 2019 г., 22:17:20 UTC+3 пользователь Valeriy Filatov написал:
Reply all
Reply to author
Forward
0 new messages