36

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.

Daniel Romero
  • 1,542
  • 1
  • 19
  • 32
  • 1
    Did you try to run `sbt clean` once? – Roman Jun 01 '15 at 07:40
  • 1
    I tried `activator clean` and `activator clean-files` but I got the same error. – Daniel Romero Jun 01 '15 at 07:46
  • I also tried removing manually the target folder and running `activator compile` and I got the same error. – Daniel Romero Jun 01 '15 at 07:53
  • 3
    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 Jun 01 '15 at 07:54
  • 5
    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.html` – Roman Jun 01 '15 at 08:01
  • You're completely right, it works. Thanks! – Daniel Romero Jun 01 '15 at 08:05
  • 2
    @Roman create the answer please, so it can be accepted and upvoted. – biesior Jun 01 '15 at 08:31

1 Answers1

70

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")
Roman
  • 5,323
  • 1
  • 27
  • 39
  • 3
    IntelliJ erroneously reports Assets.versioned() as deprecated, hasn't been fixed yet, see https://youtrack.jetbrains.com/issue/SCL-8812 – Stefan L Oct 09 '17 at 09:03