Last active
January 26, 2016 09:01
-
-
Save leafo/d09d42b105d977e71e59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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