37

我正在使用 Play 2.4.0,并且我一直在尝试按照主页上的教程进行操作:https : //playframework.com/ 适用于 Play 2.3,并且在解决了一些关于 Ebean ORM 更改的问题之后版本 2.3 到 2.4,我遇到以下错误:

Compilation error

value at is not a member of controllers.ReverseAssets

我的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>
}

还有我的routes文件:

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

我有同样的例子在 Play 2.3.9 上工作正常

而且我看不出在 2.4.0 的文档中使用公共资产有什么不同:https ://www.playframework.com/documentation/2.4.0/Assets

所以......任何帮助将不胜感激。

4

1 回答 1

70

好吧,总结一下解决方案:Play 允许您以两种不同的方式提供资产。sbt-web 引入的老式和新指纹方法。无论哪种情况,请确保在视图文件中使用正确的调用:

指纹资产

这是为游戏中的资产提供服务的推荐方式。指纹资产利用积极的缓存策略。您可以在此处阅读有关此主题的更多信息:https ://playframework.com/documentation/2.4.x/Assets

路线配置:

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

确保类型file指示为Asset

调用视图:

@routes.Assets.versioned("an_asset")


老式资产

这基本上是在引入 sbt-web 之前使用的方法。

路线配置:

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

调用视图:

@routes.Assets.at("an_asset")
于 2015-06-01T09:21:55.100 回答