I'm creating application using Scalatra and I'm using Scalate/Jade for templating. I try to add flash support to my application. I mixed FlashMapSupport into into my Servlet and I'm able to access flash helper. Anyway, if I'm trying to get it from layout I receive following error:

[error] /home/ytaras/projects/scala/scalatra-shopping-cart/target/scala-2.10/src_managed/main/scalate/templates/layouts/default_jade.scala:27: not found: value flash
[error]                         flash.get("alert").foreach
[error]                         ^
[error] one error found

The best I could do to avoid that was to use downcast to render context:

  - context.asInstanceOf[org.scalatra.scalate.ScalatraRenderContext].flash.get("alert").foreach
    - alert =>
    .alert
      .button(type="button" class="close" data-dismiss="alert") ×
      = alert

Anyway, that's definitely not a prettiest solution. Is there something I can do to fix it or it's an issue in Scalate/Jade code?

有帮助吗?

解决方案

I've just done a very simple Scalatra app using Jade, it seems to work as per the docs.

Edit: I had been working with an app generated in an earlier version of Scalatra.

In Scalatra 2.2.0, we added precompiled Scalate templates in the g8 skeleton, to give extra speed in production by default. There's an error in project/build.scala in there which causes flash context to get lost.

Add this to your project/build.scala: https://gist.github.com/anonymous/ff40cdde1a1105970f50#file-build-scala-L37-L39

We'll fix the g8 template momentarily. Sorry for the trouble.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top