Class: Happy::Extras::ActionController

Inherits:
Controller
  • Object
show all
Defined in:
lib/happy/extras/action_controller.rb

Overview

A Rails-like controller that dispatches to individual actions named in the URL.

The controller’s root URL will call the ‘index` method, any sub-path will call the method by that name. If a third path is provided, it will be assigned to params.

/ # index /foo # foo /foo/123 # foo (with params set to 123)

Constant Summary

Constants inherited from Controller

Controller::CASCADING_SETTINGS

Instance Attribute Summary

Attributes inherited from Controller

#env, #processed_path, #unprocessed_path

Attributes included from Helpers::Rendering

#output_buffer

Instance Method Summary collapse

Methods inherited from Controller

#app, #current_url, helpers, #initialize, #params, #request, #response, #root_url, #session

Methods included from Helpers::I18n

#localize, #translate

Methods included from Helpers::Rendering

#capture_template_block, #concat_output, #render, #render_resource, #render_template, #with_output_buffer

Methods included from Helpers::Html

#escape_html, #html_tag, #html_tag_attributes, #link_to, #preserve, #url_for

Methods included from Controller::Permissions

#permissions

Methods included from Controller::Configurable

#set, #settings

Methods included from Controller::Rackable

#handle_request

Methods included from Controller::Actions

#cache_control, #content_type, #halt!, #header, #layout, #max_age, #only_if_path_matches, #redirect!, #run, #serve!

Methods included from Controller::Routing

#on, #path_to_regexp

Constructor Details

This class inherits a constructor from Happy::Controller

Instance Method Details

#dispatch_to_method(name) ⇒ Object (protected)



30
31
32
33
34
35
36
37
# File 'lib/happy/extras/action_controller.rb', line 30

def dispatch_to_method(name)
  # Only dispatch to public methods
  if public_methods(false).include?(name.to_sym)
    send name
  else
    raise Errors::NotFound
  end
end

#routeObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/happy/extras/action_controller.rb', line 16

def route
  on :action do
    on :id do
      dispatch_to_method params['action']
    end

    dispatch_to_method params['action']
  end

  index
end