Reputation: 10180
I had this route in my application:
GET /assets/*file controllers.Assets.at(path="/public", file)
I used reverse route in a scala template and it worked properly:
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/bootstrap.css")">
But when I add this route for images:
GET /images/*file controllers.Assets.at(path="/public/images", file)
I get following error in scala template that worked properly:
not enough arguments for method at: (path: String, file: String)play.api.mvc.Call.
Unspecified value parameter file.
I can not use controllers.Assets.at twice in route in Play Framework 2 or something else?
Upvotes: 2
Views: 3178
Reputation: 7288
As stated in the documentation, I believe you can add 1 or more routes for your assets.
Here is the important part that I think you missed:
This action will look-up the file and serve it, if it exists.
Note, if you define asset mappings outside “public,” you’ll need to tell sbt about it, e.g. if you want:
GET /assets/*file Assets.at("public", file)
GET /liabilities/*file Assets.at("foo", file)
you should add this to Build.scala:
playAssetsDirectories <+= baseDirectory / "foo"
And this for using the reverse routing:
However, if you define two mappings for the Assets.at action, like this:
GET /javascripts/*file Assets.at("public/javascripts", file)
GET /images/*file Assets.at("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")">
EDIT:
Try to change your CSS link into this:
<link rel="stylesheet" media="screen" href="@routes.Assets.at("/public","stylesheets/bootstrap.css")">
Upvotes: 6