Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework @routes.Assets.at Compilation Error

I'm using Play 2.4.0 and I've been trying to follow the tutorial from the main page: https://playframework.com/ which is for Play 2.3 and after solving a couple of issues regarding changes in the Ebean ORM from version 2.3 to 2.4, I'm stuck with the following error:

Compilation error  value at is not a member of controllers.ReverseAssets 

My index.scala.html:

@(message: String)  @main("Welcome to Play") {      <script type='text/javascript' src="@routes.Assets.at("javascripts/index.js")"></script>      <form action="@routes.Application.addPerson()" method="post">         <input type="text" name="name" />         <button>Add Person</button>     </form>      <ul id="persons">     </ul> } 

And my routes file:

# Routes # This file defines all application routes (Higher priority routes first) # ~~~~  # Home page GET         /                    controllers.Application.index()  POST        /person              controllers.Application.addPerson()  GET         /persons             controllers.Application.getPersons()  # Map static resources from the /public folder to the /assets URL path GET         /assets/*file        controllers.Assets.versioned(path="/public", file: Asset) 

I have this same example working ok with Play 2.3.9

And I can't see anything different about working with public assets in the docs for the 2.4.0: https://www.playframework.com/documentation/2.4.0/Assets

So... any help would be appreciated.

like image 267
Daniel Romero Avatar asked May 31 '15 20:05

Daniel Romero


1 Answers

Alright, to sum up the solution: Play lets you serve your assets in two different ways. The old fashioned and the new fingerprinted method introduced with sbt-web. In either case make sure you use right call in your view files:

Fingerprinted assets

This is the recommended way to serve assets in play. Fingerprinted assets make use of an aggressive caching strategy. You can read more about this topic here: https://playframework.com/documentation/2.4.x/Assets

routes config:

GET     /assets/*file               controllers.Assets.versioned(path="/public", file: Asset) 

Make sure the type of file is indicated as Asset

call in views:

@routes.Assets.versioned("an_asset") 


Old fashioned assets

This is basically the method used before the introduction of sbt-web.

routes config:

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

call in views:

@routes.Assets.at("an_asset") 
like image 134
Roman Avatar answered Sep 20 '22 18:09

Roman