Skip to content

Instantly share code, notes, and snippets.

@danieldietrich
Created March 11, 2012 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieldietrich/2018403 to your computer and use it in GitHub Desktop.
Save danieldietrich/2018403 to your computer and use it in GitHub Desktop.
Url Path Binding w/o Boilerplate
package models
object Account extends BindableEnum {
val Company, Sales = Value // create enumerated values
}
package models
import play.api.mvc.PathBindable
abstract class BindableEnum extends Enumeration {
implicit def bindableEnum = new PathBindable[Value] {
def bind(key: String, value: String) =
values.find(_.toString.toLowerCase == value.toLowerCase) match {
case Some(v) => Right(v)
case None => Left("Unknown url path segment '" + value + "'")
}
def unbind(key: String, value: Value) = value.toString.toLowerCase
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment