Big_Data
Big_Data

Reputation: 322

i have wriiten a logout code in welcome.scala.html page but getting errors in that page how can i write the code for it

localhost sbt

Cannot use a method returning play.api.mvc.ActionBuilder[play.api.mvc.Request,play.api.mvc.AnyContent] as a Handler for requests

I am trying to come back to the index.scala.html page after clicking on the logout button in welcome.scala.html but its showing a compilation error while executing.

This is the welcome.scala.html page:

<html>
    <body>
welcome to homepage
        <a href="@routes.HomeController.logout()">
        <input type="submit" value="Logout">
    </body>
</html>

This is the index.scala.html page:

@main("Welcome to Play") {
}
<html>
    <body>
        username<input type="text" name="uname">
        password<input type="password" name="pword">
        <a href="@routes.HomeController.welcome()">
            <div class="my-button">Submit</div>
        </a>
    </body>
</html>

This is HomeController:

@Singleton
class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
    def index = Action {
        Ok(views.html.index())
    }
    def welcome = Action
    {
        Ok(views.html.welcome())
    }
    def logout = Action
    {
        Ok(views.html.index())
    }
}

This is the routes file:

GET     /                                 controllers.HomeController.index
GET     /welcome                          controllers.HomeController.welcome
GET     /logout                           controllers.HomeController.logout




this is main.scala.html code


@(title: String)(content: Html)
<!DOCTYPE html>
<html lang="en">
<head>
<title>@title</title>
<link rel="stylesheet"media="screen"href="@routes.Assets.versioned("stylesheets/main.css")">
 <link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
<script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script>
</head>
<body>
@content
</body>
</html>


got this error after editing the routes page
Cannot use a method returning play.api.mvc.ActionBuilder[play.api.mvc.Request,play.api.mvc.AnyContent] as a Handler for requests

Upvotes: 0

Views: 120

Answers (1)

mfirry
mfirry

Reputation: 3692

Seems like you've got a small error on your routes file:

Change this: GET /logout controllers.HomeController.index into GET /logout controllers.HomeController.logout

And it should just work.

Upvotes: 1

Related Questions