Play reverse routing - getting absolute url

2019-08-10 22:32发布

How can I get the absolute URL in play 2.2 scala when doing the following:

val promoLink = routes.Promotions.promotionsCategory(DOCID, slug)


//routes file

GET /promotions/:DOCID:/slug     controllers.Promotions.promoCat(DOCID, slug)

As it stands I get a "found : play.api.mvc.Call" type mismatch on expecting a string

thanks

1条回答
孤傲高冷的网名
2楼-- · 2019-08-10 22:45

I suppose your promoLink should be a String containing an URL? Your question sounds a bit unclear.

If so then you probably need this:

val promoLink = routes.Promotions.promotionsCategory(DOCID, slug).absoluteURL(false)(request)

false in the .absoluteURL(false) stands for the isSecure parameter which will give you http or https url.

If you have an implicit request in scope you may omit the last (request) part

查看更多
登录 后发表回答