Play Framework Routes Error: "there are not enough arguments for the method in ..."

There are my routes. The second comment is commented.

GET /assets/*file controllers.Assets.at(path="/public", file) #GET /partials/*file controllers.Assets.at(path="/public/partials", file) 

( I want: to make my html files inside the "/public/partials" folder accessible over the Internet, just like for assets )

As soon as I uncomment the second line , it will get errors due to this line (from my index.scala.html ):

 <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")"> 

The error is here:

there are not enough arguments for the at: (path: String, file: String) play.api.mvc.Call method. Unspecified value specification file.

Q: What is wrong?

UPDATE:

Other words: I want to make my url shorter by providing this mapping. Otherwise, I should use this url: 'assets/partials/welcome.html' instead (which I would like to use): 'partials/welcome.html' .

Just another mapping that will make my URLs shorter.

It makes sense when I need to contact those from the JS part, it looks like there are two applications in one (1.play one, 2. js one), there are also routes there, two roots. For JS, I assume that I'm already in / public (or in assets) - this is the root for the js app.

And I wonder why this is not working.

+6
source share
1 answer

In games :

Reverse Routing for Public Assets

For any controller displayed in the routes file, a reverse controllers.routes.Assets is created in controllers.routes.Assets. You use this to cancel the URL required to get a public resource. For example, from the template:

 <script src="@routes.Assets.at("javascripts/jquery.js")"></script> 

This will result in the following result:

 <script src="/assets/javascripts/jquery.js"></script> 

Please note that we will not specify the first folder parameter when returning the route. This is because our routes file defines one mapping for the Assets.at action, where the folder option is fixed. Therefore, it clearly does not need to be indicated.

However, if you define two mappings for the Assets.at action, for example:

 GET /javascripts/*file controllers.Assets.at(path="/public/javascripts", file) GET /images/*file controllers.Assets.at(path="/public/images", file) 

Then you will need to specify both parameters when using a reverse router:

 <script src="@routes.Assets.at("/public/javascripts", "jquery.js")"></script> <image src="@routes.Assets.at("/public/images", "logo.png")"> 

Any static html in the public / partials directory will be publicly available in /assets/partials/someHtml.html. So, strictly speaking, you do not need the route / partials / * file

+10
source

Source: https://habr.com/ru/post/958706/


All Articles