Module: Tap::Controller::RestRoutes
- Defined in:
- lib/tap/controller.rb
Overview
Adds REST routing (a-la Rails) to a Tap::Controller.
class Projects < Tap::Controller
include RestRoutes
# GET /projects
def index...
# GET /projects/*args
def show(*args)...
# GET /projects/arg;edit/*args
def edit(arg, *args)...
# POST /projects/*args
def create(*args)...
# PUT /projects/*args
def update(*args)...
# DELETE /projects/*args
def destroy(*args)...
end
Instance Method Summary collapse
Instance Method Details
#route ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tap/controller.rb', line 47 def route blank, *args = request.path_info.split("/").collect {|arg| unescape(arg) } action = case request.request_method when /GET/i case when args.empty? :index when args[0] =~ /(.*);edit$/ args[0] = $1 :edit else :show end when /POST/i then :create when /PUT/i then :update when /DELETE/i then :destroy else raise ServerError.new("unknown request method: #{request.request_method}") end [action, args] end |