36
votes

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.

1
Did you try to run sbt clean once?Roman
I tried activator clean and activator clean-files but I got the same error.Daniel Romero
IIRC, I had a similar error migrating to play 2.4. My assets route looks like this: GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset). Note the use of versioned instead of at. Maybe this helps. If not it might be helpful if you post your routes configuration.Roman
Forgot to mention that you also have to change @routes.Assets.at("javascripts/index.js") to @routes.Assets.versioned("javascripts/index.js") in your index.scala.htmlRoman
@Roman create the answer please, so it can be accepted and upvoted.biesior

1 Answers

70
votes

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")