Skip to content

Instantly share code, notes, and snippets.

@leafo
Last active January 26, 2016 09:01
Show Gist options
  • Save leafo/d09d42b105d977e71e59 to your computer and use it in GitHub Desktop.
Save leafo/d09d42b105d977e71e59 to your computer and use it in GitHub Desktop.
local app = lapis.Application()
app:match("/my-thing", respond_to {
on_error = function(self)
-- the view will have access to self.errors
return { render = true }
end,
before = function(self)
-- do everything to set up the view, since if we get an error we need to rerender
self.the_object = TheObjects:find(self.params.id)
end,
GET = function(self)
-- this function should have to do nothing, since before set it up
return { render = true }
end,
POST = function(self)
assert_csrf(self)
assert_valid(self.params, {
{"name", exists = true, min_length = 1, max_length = 500}
-- .. etc
})
self.the_object:update({
name = self.params.name
})
return { redirect_to = self:url_for(self.the_object) }
end,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment