I'm trying to use javascriptRoutes
in Play 2 (Scala) and I am getting an error (see below). Here is what I did:
Add javascriptRoutes
method to Application
controller
def javascriptRoutes = Action { implicit request =>
import routes.javascript._
Ok(Routes.javascriptRouter("jsRoutes")(Orders.searchProducts))
.as("text/javascript")
}
Add route to routes
file
GET /assets/javascripts/routes controllers.Application.javascriptRoutes
Add <script>
import to main.scala.html
<head>
...
<script type="text/javascript" src="@routes.Application.javascriptRoutes"></script>
...
</head>
With these changes in place I am getting the following error in the JavaScript console:
GET http://localhost:9000/assets/javascripts/routes 404 (Not Found)
Uncaught ReferenceError: jsRoutes is not defined
What am I missing?
In the meantime I have found an other post related to this ->
Unable to resolve reverse routing methods in IntelliJ
I had to remove some info from the project config to get the following folders to become part of source route ->
File -> Project Structure
Select Sources in Right Pane
Add Source folder target/scala-XXX/classes_managed target/scala-XXX/src_managed/main
wrong order within the conf/routes file may cause the issue.
there is a hint:
http://grokbase.com/t/gg/play-framework/1348rbs2vk/2-1-scala-javascript-router-404
once I adjusted the order according to the hint:
the issue was fixed.