Redirect in Scala play framework

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Redirect in Scala play framework



I have a problem with Redirect in Scala play framework.



How can I redirect to view BooksController.index() ? In documentation they suggest to use Redirect but I don't know how.


def edit(Id: Int) = Action
val book: Book = Book.findById(Id)
Ok(views.html.edit())


def update = Action
implicit request =>
val (id, title, price, author) = bookForm.bindFromRequest.get
val book: Book = Book.findById(id)
book.id = id
book.title = title
book.price = price
book.author = author
Redirect(routes.BooksController.index())



Now can recognize --> import play.api.mvc.Results._
But i have an error --> "object java.lang.ProcessBuilder.Redirect is not a value"




2 Answers
2



If you would really like to continue using reverse routing in your code instead of having string uri values all over the place, see this:
Redirect with Bad Request Status.
The Redirect function accepts only a String or Call.

Try the following steps:

0) Add in the BookController


import play.api.mvc._



1) Add the following string in your route config file(hard disk location: controllers/BooksController)


GET /redirectedPage controllers.BooksController.index



2) Define a variable in the BookController


val Home = Redirect(routes.BookController.index())



3) Describe in the BookController


def update = Action
implicit request => Home



Also do "sbt clean; sbt compile" to recompile auto-calls in ReverseRoutes.scala.

Well done.



The last line in the update action is the Redirect call which redirects to BooksController index route


update


Redirect


index


import play.api.mvc.Results._

Redirect(routes.BooksController.index())





Yes, but doesnt work for me. Cant recognize word Redirect
– Michael
Jul 8 at 19:13





@Michael import import play.api.mvc.Results._
– pamu
Jul 8 at 19:20


import play.api.mvc.Results._





Thank you, now can recognize but i have an error "object java.lang.ProcessBuilder.Redirect is not a value"
– Michael
Jul 8 at 20:18






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered