My controller actions use a custom action that looks like:
class ActionWithContext @Inject()(....)
extends ActionBuilder[ContextAwareRequest] {
def invokeBlock[A](request: Request[A], block: (ContextAwareRequest[A]) => Future[Result]) = {
...
}
}
class ContextAwareRequest[A](val context: MyContext, request: Request[A]) extends WrappedRequest[A](request)
My controller looks like:
import play.api.i18n.{MessagesApi, I18nSupport, Messages}
import play.api.i18n.Messages.Implicits._
class WebsiteController @Inject() (val messagesApi: MessagesApi, actionWithContext: ActionWithContext, ..)
extends BaseController with I18nSupport {
def edit(websiteId: Int) = actionWithContext { request =>
val model = ..
Ok(views.html.backend.websites.edit(model)(request.context))
}
}
The view page looks like:
@(form: Form[controllers.WebsiteForm])(implicit context: MyContext, m: Messages) {
}
I am getting the error:
not enough arguments for method apply: (implicit context: com.example.services.components.MyContext, implicit m: play.api.i18n.Messages)play.twirl.api.HtmlFormat.Appendable in class edit.
[error] Unspecified value parameter m.
[error] Ok(views.html.websites.edit(model)(request.context))
[error]
I tried passing in the messageApi like:
Ok(views.html.websites.edit(model)(request.context, messageApi))
But I then got a type mismatch error between Messages and MessageApi.
What should I be doing?
P.S I am not even using messages in my views, but I am using the Form helpers which I guess use messages under the covers...
It looks like you're trying to pass one implicit parameter explicitly and the other implicitly. You have to either pass them both explicitly:
Ok(views.html.websites.edit(model)(request.context, implicitly[Messages]))
Or both implicitly:
implicit val context = request.context
Ok(views.html.websites.edit(model))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With