Skip to content

Instantly share code, notes, and snippets.

@tizoc
Created February 14, 2011 14:23
Show Gist options
  • Save tizoc/825936 to your computer and use it in GitHub Desktop.
Save tizoc/825936 to your computer and use it in GitHub Desktop.
# when handling a request on rack, thread_locals[:request] is set
module FrameworkStuff
def request
thread_locals[:request]
end
end
class Auth
extend FrameworkStuff
include FrameworkStuff
route '/signup/', :signup
route '/logout/', :logout
def signup
if request.post?
# process params
redirect '/home' if validated
end
render 'login.haml' # if it is a get or didn't validate you render the login firm
end
# ...
end
class Site
extend FrameworkStuff
include FrameworkStuff
route '/', :home
route '/some_subsection/', SomeSubsectionClass # passes this to a SomeSubsectionClass instance
def home
render 'home.haml'
end
end
class SomeSubsectionClass
extend FrameworkStuff
include FrameworkStuff
route '/', :list
route '/new/', :new
def list
objects = Model.all
render 'list.haml', objects: objects
end
def new
if request.post?
# handle request
redirect :list if validated?
end
renter 'blah.haml'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment