Skip to content

Instantly share code, notes, and snippets.

@d6y
Created October 24, 2011 13:23
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 d6y/1309016 to your computer and use it in GitHub Desktop.
Save d6y/1309016 to your computer and use it in GitHub Desktop.
Unsubscribe redo
object Unsubscribe {
/* A menu for Lift's Sitemap which maps /unsubscribe/{uuid} to two
functions: 1) given a uuid, lookup a Subscription instance
2) given a Subscription instance, create the link address... */
val menu = Menu.param[Subscription]("Unsubscribed", "Unsubscribed",
uuid => Subscription.find(By(Subscription.uuid, uuid)),
s => s.uuid ) / "unsubscribed" >> Hidden
/* The Loc(ation) part of the menu is what we're going to work with... */
lazy val loc: Loc[Subscription] = menu.toLoc
/* Turn HTML element with id="undo" into a link, by deleting the current record and
creating a link that when clicked will re-create the subscription in the database... */
def render = "#undo" #> loc.currentValue.map { s =>
s.delete_!
SHtml.link("/resubscribed", () => s.duplicate, Text("undo") )
}
// the duplicate method copies the fields of s into a new DB row.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment