[英]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: 我正在使用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
My index.scala.html
: 我的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
档案:
# 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 我有这个相同的例子与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 在2.4.0的文档中,我看不出与使用公共资产有什么不同: https : //www.playframework.com/documentation/2.4.0/Assets
So... any help would be appreciated. 所以...任何帮助将不胜感激。
Alright, to sum up the solution: Play lets you serve your assets in two different ways. 好的,总结一下解决方案:Play可以让您以两种不同的方式为您的资产提供服务。 The old fashioned and the new fingerprinted method introduced with sbt-web. 用sbt-web引入的老式和新的指纹方法。 In either case make sure you use right call in your view files: 在任何一种情况下,请确保在视图文件中使用正确的调用:
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 您可以在此处阅读有关此主题的更多信息: 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
确保file
类型显示为“ Asset
call in views: 来电观点:
@routes.Assets.versioned("an_asset")
This is basically the method used before the introduction of sbt-web. 这基本上是在引入sbt-web之前使用的方法。
routes config: 路由配置:
GET /assets/*file controllers.Assets.at(path="/public", file)
call in views: 来电观点:
@routes.Assets.at("an_asset")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.