Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Play w/ Scala: Url Path Binding
package models
import play.api.mvc.PathBindable
object Account extends Enumeration {
val Company, Sales = Value // create enumerated values
// url path binding (routes)
implicit def bindableAccount = new PathBindable[Account.Value] {
def bind(key: String, value: String) =
Account.values.find(_.toString.toLowerCase == value.toLowerCase) match {
case Some(v) => Right(v)
case None => Left("Unknown account type '" + value + "'")
def unbind(key: String, value: Account.Value) = value.toString
@(account: models.Account.Value)
@main() {
<p>Look ma, bound url path to @account</p>
# Signup
GET /signup/:account controllers.SignUp.form(account: models.Account.Value)
package controllers
import models._, play.api.mvc._, views._
object SignUp extends Controller {
def form(account: Account.Value) = Action {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.