Module: Ruil::Controller
- Included in:
- Authorizer
- Defined in:
- lib/ruil/controller.rb
Overview
The module Controller allow us to a group the creation of resources in classes.
Usage
class MyController
include Ruil::Controller
resource 'GET', '/mycontroller/:your_name' do |request|
ok :text, 'hello ' + request[:path_info_params][:your_name]
end
end
Constant Summary collapse
- @@content_types =
{ :html => 'text/html', :xhtml => 'application/xhtml+xml', :text => 'plain/text', :json => 'application/json' }
Instance Method Summary collapse
-
#ok(type, body, headers = {}) ⇒ Object
Respond OK.
-
#redirect(request, url) ⇒ Object
Redirect the request to other URL.
- #resource(methods, pattern, acl = false, &block) ⇒ Object
Instance Method Details
#ok(type, body, headers = {}) ⇒ Object
Respond OK
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ruil/controller.rb', line 44 def ok(type, body, headers = {}) # Apply custom skins. Ruil::Skin.call body if [:html, :xhtml].include? type # Setup headers. headers = { 'ContentType' => @@content_types[type] || 'plain/text' }.merge(headers) # Respond. [200, headers, [body]] end |
#redirect(request, url) ⇒ Object
Redirect the request to other URL.
36 37 38 39 |
# File 'lib/ruil/controller.rb', line 36 def redirect(request, url) headers = {'Location'=> url + "?redirected_from=" + request.path_info} [302, headers, []] end |