kmoormann
kmoormann

Reputation: 180

Too many arguments in Play2 template

I have a simple application that in the process of building, and am running into a complication error that I cannot determine why. (Full disclosure: this is my first scala/play project)

the error reads:

too many arguments for method apply: ()play.api.templates.Html in object dailyChart

there is one argument to the view that I can surmise a List of GlucoseReadings. The controller is passing a list of GlucoseReadings provided by the model so I am at a lost as to why there are too many arguments when the number of arguments and types match.

I have a simple model, controller and view that will ultimately display a simple chart of glucose readings for a day.

The model is as follows (in file GlucoseReadings.scala):

package models

import play.api.db._
import play.api.Play.current

import anorm._
import anorm.SqlParser._

import org.joda.time._
import java.util.Date

case class GlucoseReading(
    id: Int, mgdl: Int, recordTime: DateTime
)

object GlucoseReading {

  val glucoseReading = {
    get[Int]("id") ~
    get[Int]("mgdL") ~
    get[Date]("recordTime") map {
            case id~mgdL~recordTime => GlucoseReading(id, mgdL, new DateTime(recordTime))
        }
  }

  def dailyReadings(date: DateTime): List[GlucoseReading] = {
        DB.withConnection { implicit connection =>
        SQL("""
                SELECT 
          id,
                recordTime,
          mgDl
                FROM GlucoseReading
                ORDER BY recordDate DESC
            """).as(glucoseReading *)
    }
  }
}

the controller (in file GlucoseReadingsController.scala):

package controllers

import play.api.mvc._
import play.api.data._
import play.api.data.Forms._

import org.joda.time._

import models.GlucoseReading

object GlucoseReadingsController extends Controller {

  def daily(year: Int, month: Int, day: Int) = Action {
    val date = new DateTime(year, month, day,0,0)
    val readings = GlucoseReading.dailyReadings(date)
    Ok(views.html.dailyChart(readings))
  }

}

and the view (in file dailyChart.scala.html):

@(readings: List[GlucoseReading])

@import helper._

@main("Day With Read") {

    <ul>
        @reading.map { reading =>
            <li>
                I'm a glucose reading
            </li>
        }
    </ul>    
}

Based on comments the main template is below

@(title: String)(content: Html)

<!DOCTYPE html>

<html>
    <head>
        <title>@title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
    </head>
    <body>
        @content
        <script src="http://code.jquery.com/jquery.js"></script>
        <script src="js/bootstrap.min.js"></script>
    </body>
</html>

Upvotes: 0

Views: 2235

Answers (1)

Alex Yarmula
Alex Yarmula

Reputation: 10657

The only problem I can see is:

<ul>
    @reading.map { reading =>
        <li>

It should compile just fine one you change that to @readings.map. If not, exit play and remove your target directory, then try again.

Upvotes: 1

Related Questions