Reputation: 41909
As I'm working on implementing TinyUrl, I want to redirect users to a webpage based on the input hash.
def getTask(hash: Int) = Action {
val url: Option[String] = Task.getTask(hash)
// redirect to show(url)
}
However, I don't know how to redirect the user to an external URL.
I saw this related post, but I encountered this compile-time error when I used redirect
not found: value redirect
Upvotes: 3
Views: 1982
Reputation: 18706
redirect
doesn't exist.
But Redirect
, which is a member of the play.api.mvc
package, does.
Here's an example of what your action should look like:
import play.api.mvc._
def getTask(hash: Int) = Action {
val url: Option[String] = Task.getTask(hash)
url match {
case Some(url) => Redirect(url)
case None => NotFound("This URL leads nowhere. :(")
}
}
Upvotes: 5