[dancer-users] Retrieving the current prefix?

Morse, Richard E.,MGH REMORSE at mgh.harvard.edu
Thu Jan 21 17:12:23 EST 2021


Hi! I'm starting to learn Dancer2. One question I have is whether it is possible to retrieve the current prefix in some way?

In particular, I am showing a listing of things, and I would like to add an edit link. I have the following setup:

    prefix '/foo';

    get '/' => sub { forward '/foo'; };
    get ''  => sub {
        my @rows = database->quick_select(...);
        foreach my $r (@rows) {
            $r->{'edituri'} = uri_for( '/foo/' . $r->{'id'});
        }
        template 'foo.tt', { 'listing' => \@rows, 'adduri' => uri_for( '/foo/add' ) };
    };

I feel like I should be able to get rid of the '/foo' bit in the `forward` and `uri_for` calls — if this changes, I now need to change it in multiple places, and could introduce a typo. I tried doing `uri_for( prefix . '/' . $r->{'id'})`, but that didn't work.

If there isn't some obvious way to do this, how to other people manage these kinds of things?

Thanks,
Ricky
The information in this e-mail is intended only for the person to whom it is addressed. If you believe this e-mail was sent to you in error and the e-mail contains patient information, please contact the Mass General Brigham Compliance HelpLine at http://www.massgeneralbrigham.org/complianceline . If the e-mail was sent to you in error but does not contain patient information, please contact the sender and properly dispose of the e-mail.



More information about the dancer-users mailing list