У меня есть действие, которое должно вызываться для нескольких URL.
def index(signupMessage:Option[String]) = addToken {
silhouette.UserAwareAction { implicit request =>
println(s"index action called with request ${utilities.printPlayHttpRequest(request)}")
println(s"index page's argument "+signupMessage)
val Token(name, value) = CSRF.getToken.get
println(s"Token name ${name}, value ${value}")
Ok(views.html.index(/*signupMessage:Option[String]*/messagesApi("app.title")(langs.availables(0))))
}
}
Следующие URL должны соответствовать одному действию
/
/home
/home;signup="success"
/home;signup="error"
Я создал маршруты в файле routes.conf
следующим образом, но код не компилируется. Что я делаю не так
GET / controllers.HomeController.index(signup = None)
GET /home/:signup controllers.HomeController.index(signup:Option[String])
Ошибка
C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:12: No URL path binder found for type Option[String]. Try to implement an implicit PathBindable for this type.
[error] GET /home/:signup controllers.HomeController.index(signup:Option[String])
[error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:12: not enough arguments for method implicitly: (implicit e: play.api.mvc.PathBindable[Option[String]])play.api.mvc.PathBindable[Option[String]].
[error] Unspecified value parameter e.
[error] GET /home/:signup controllers.HomeController.index(signup:Option[String])
[error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:12: No URL path binder found for type Option[String]. Try to implement an implicit PathBindable for this type.
[error] GET /home/:signup controllers.HomeController.index(signup:Option[String])
[error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:12: not enough arguments for method implicitly: (implicit e: play.api.mvc.PathBindable[Option[String]])play.api.mvc.PathBindable[Option[String]].
[error] Unspecified value parameter e.
[error] GET /home/:signup controllers.HomeController.index(signup:Option[String])
[error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:7: method index is defined twice;
[error] the conflicting method index was defined at line 22:9
[error] GET / controllers.HomeController.index(signup = None)
[error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:7: type mismatch;
[error] found : String
[error] required: Option[String]
[error] GET / controllers.HomeController.index(signup = None)
[error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:7: type mismatch;
[error] found : None.type
[error] required: String
[error] GET / controllers.HomeController.index(signup = None)
[error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:12: No URL path binder found for type Option[String]. Try to implement an implicit PathBindable for this type.
[error] GET /home/:signup controllers.HomeController.index(signup:Option[String])
[error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:12: not enough arguments for method fromPath: (implicit binder: play.api.mvc.PathBindable[Option[String]])play.core.routing.Param[Option[String]].
[error] Unspecified value parameter binder.
[error] GET /home/:signup controllers.HomeController.index(signup:Option[String])
[error] 9 errors found
[error] (compile:compileIncremental) Compilation failed
[error] application -
! @796k0gd0d - Internal server error, for (GET) [/] ->
play.sbt.PlayExceptions$CompilationException: Compilation error[No URL path binder found for type Option[String]. Try to implement an implicit PathBindable for this type.]