テンプレートに渡す前に暗黙の値をオーバーライドする必要がありますが、その方法がわかりません。このようなもの:
/* This Session User and City setup */
case class MySession(user: Option[User] = None, city: Option[City] = None) {}
/* Trait for Controllers */
trait CMySession {
implicit def mySession[A](implicit request: Request[A]) : MySession = {
val userOpt = /*... get from session user here ...*/
val cityOpt = /*... get from session city here ...*/
MySession(user = userOpt, city = cityOpt)
}
}
/* Controller */
def showCity(city_name: String) = Action { implicit request =>
// Get city
val cityOpt = { for (c <- mySession.city) yield Some(c) } getOrElse Cities.getByName(city_name)
// Check if NO City in session, but we get it from request
if (mySession.city != cityOpt) {
// NEED some how override implicited mySession value here for template?!
}
Ok(views.html.showCity())
}}
手がかりをありがとう!