Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework. Routes. Error: "not enough arguments for method at..."

There are my routes. Second one is commented.

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

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

( What I want is: to make my html files that are located inside "/public/partials" folder to be available through the web, same way as it's made for assets )

As soon as I uncomment 2nd 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")">

Error is like here:

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

Q: What's wrong?

UPDATE:

Another words: I want to make my url shorter by providing that mapping. Otherwise I have to use this url: 'assets/partials/welcome.html' instead of that one (that I would like to use): 'partials/welcome.html'.

Just one more mapping that would make my urls shorter.

It make sense when I need to reach those from JS part, it's like having two applications in one (1.play one, 2. js one), there too routings, two roots. For JS one I'm assuming that I'm already in /public (or in assets) - this is a root for js app.

And I wonder why it doesn't work.

like image 533
ses Avatar asked Nov 23 '13 23:11

ses


1 Answers

From the play docs:

Reverse routing for public assets

As for any controller mapped in the routes file, a reverse controller is created in controllers.routes.Assets. You use this to reverse the URL needed to fetch a public resource. For example, from a template:

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

This will produce the following result:

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

Note that we don’t specify the first folder parameter when we reverse the route. This is because our routes file defines a single mapping for the Assets.at action, where the folder parameter is fixed. So it doesn’t need to be specified explicitly.

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

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 the 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 would be publicly available at /assets/partials/someHtml.html. So strictly speaking, you don't need the /partials/*file route

like image 150
mantithetical Avatar answered Jan 04 '23 04:01

mantithetical