Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play framework - Scala, Method is defined twice

I want to map multiple URLs into an overloaded controller method as below. But I get the error "Method account is defined twice". So, is it possible to do this in scala - play framework?

GET     /order/:userId             controllers.Application.account(userId)       
GET     /order/:userId/:date       controllers.Application.account(userId, date)
like image 892
Faruk Sahin Avatar asked Sep 20 '12 15:09

Faruk Sahin


1 Answers

Because of the way the reverse routing works, you need to specify both parameters to use account like that. Here's an example that works:

In Application.scala:

def account(userId: String, date: String) = Action {
  Ok(userId + " and " + date)
}

In routes:

GET /order/:userId           controllers.Application.account(userId, date="")
GET /order/:userId/:date     controllers.Application.account(userId, date)
like image 146
Andrew Conner Avatar answered Nov 02 '22 05:11

Andrew Conner