Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.