forked from manveru/ramaze
-
Notifications
You must be signed in to change notification settings - Fork 37
Handling HTTP verbs separately
Michel Blanc edited this page Aug 11, 2012
·
1 revision
You can inspect request.env['REQUEST_METHOD']
. Here is a (contrived)
example that calls different methods depending on HTTP method used :
class Robot < Ramaze::Controller
def index(method, *args)
real_method = request.env['REQUEST_METHOD'].downcase
real_method << "_" + method.downcase
send(real_method, args) if self.class.method_defined?(real_method)
end
def get_me(*args)
"Here is #{args.join ' '}"
end
def post_me(*args)
"Sorry, can't post you #{args.join ' '}. Postoffice is closed."
end
end
This will be used like this :
$ curl http://localhost:7000/robot/me/a/drink
Here is a drink
$ curl -d "" http://localhost:7000/robot/me/a/letter
Sorry, can't post you a letter. Postoffice is closed.
- Website
- Google Groups
- User Guide
- [#ramaze on the Freenode network] (http://webchat.freenode.net/?channels=ramaze)