Class: Anorexic::StubRESTCtrl

Inherits:
Object
  • Object
show all
Defined in:
lib/anorexic/handlers/stubs.rb

Overview

a skeleton for a RESTful controller class

you dont have to inherit this or use this, this is stub code.

it can also be used for non RESTful requests by utilizing only the index method or adding public methods that aren't RESTful reserved (and don't start with '_').

if a method returns false, a 404 error (not found) is assumed. and routes continue to search.

otherwise, the method's return value is added to the response body. Normally, the method will return a String object.

methods should return the response's body string as their last value, unless they have correctly edited the response (in which case they should return `true`).

Instance Method Summary collapse

Constructor Details

#initializeStubRESTCtrl

every request that routes to this controller will create a new instance


21
22
# File 'lib/anorexic/handlers/stubs.rb', line 21

def initialize
end

Instance Method Details

#afterObject

called after request is completed

if method returns false (not nil), the request body is cleared, the controller exists and routes continue searching


65
66
67
# File 'lib/anorexic/handlers/stubs.rb', line 65

def after
  true
end

#beforeObject

called before request is called

if method returns false (not nil), controller exists and routes continue searching


58
59
60
# File 'lib/anorexic/handlers/stubs.rb', line 58

def before
  true
end

#deleteObject

called when request is DELETE (or params == 'delete') and request.params exists


50
51
52
# File 'lib/anorexic/handlers/stubs.rb', line 50

def delete
  "delete called - deleting object #{params[:id]}"
end

#indexObject

called when request is GET and params isn't defined


25
26
27
# File 'lib/anorexic/handlers/stubs.rb', line 25

def index
  "Hello World!"
end

#newObject

called when request is GET and params == “new” (used for the “create new object” form).


35
36
37
# File 'lib/anorexic/handlers/stubs.rb', line 35

def new
  "Should we make something new?"
end

#saveObject

called when request is POST or PUT and params isn't defined params == “new”


40
41
42
# File 'lib/anorexic/handlers/stubs.rb', line 40

def save
  "save called - creating a new object."
end

#showObject

called when request is GET and params exists


30
31
32
# File 'lib/anorexic/handlers/stubs.rb', line 30

def show
  "nothing to show for id - #{params[:id]} - with parameters: #{params.to_s}"
end

#updateObject

called when request is POST or PUT and params exists and isn't “new”


45
46
47
# File 'lib/anorexic/handlers/stubs.rb', line 45

def update
  "update called - updating #{params[:id]}"
end