Compilation error: missing arguments for method apply in class newPost; follow this method with `_' if you want to treat it as a partially applied function
I don't understand how template handling methods have to look like and what complier require of me.
https://github.com/flatlizard/blog
controller:
def addPost = Action{ implicit request =>
Ok(views.html.newPost(postForm))
}
def createPost = Action { implicit request =>
postForm.bindFromRequest.fold(
hasErrors => BadRequest,
success => {
Post.create(Post(new Date, success.title, success.content))
Ok(views.html.archive("my blog", Post.all))
})
}
routes:
GET /archive/new controllers.Application.addPost
POST /archive controllers.Application.createPost
view:
@(postForm: Form[Post])(content: Html)(implicit messages: Messages)
@import helper._
@form(routes.Application.createPost) {
@inputDate(postForm("date"))
@textarea(postForm("title"))
@textarea(postForm("content"))
<button id="submit" type="submit" value="Submit" class="btn btn-primary">Submit</button>
}
UPDATE
I solved problem adding the following imports in controller file:
import play.api.i18n.Messages.Implicits._
import play.api.Play.current
See Play 2.4 migration: https://www.playframework.com/documentation/2.4.x/Migration24#I18n
I solved problem adding the following imports in controller file:
See Play 2.4 migration: https://www.playframework.com/documentation/2.4.x/Migration24#I18n
Update
Actually this is a bad way cause here used Play.current which will become deprecated soon. Here another solution using dependency injection:
routes:
controller:
https://www.playframework.com/documentation/2.4.x/ScalaDependencyInjection
Compilation error
Your view expects three parameters to be passed, but you are passing only one. To solve your compilation error, change the signature in your view from
@(postForm: Form[Post])(content: Html)(implicit messages: Messages)
to@(postForm: Form[Post])(implicit messages: Messages)
.Parameters and views
The second parameter in your example
(content: Html)
is used when you combine several views:index.scala.html
main.scala.html
Call in controller
In this example you are passing "Some text" to index view. Index view then calls main view passing another two parameters.
title
andcontent
, wherecontent
is the html in between the curly braces of index.scala.html (<div>@text</div>
)Finally implicit parameters:
(implicit messages: Messages)
must be somewhere in scope to be passed implicitly to your view. For example like this in your controller: