Module: Picombo::Controllers

Defined in:
lib/core/core.rb,
lib/controllers/template.rb,
lib/controllers/error/404.rb

Overview

Controller Module

Controllers are the front level classes that expose your app to the web. They pass information to the model, retrieve information from the model, and pass data to views, which contain the final output for users.

Calling Controllers

Controllers are called via URIs, i.e. example.com/foobar/baz

  • Segment #1 is the controller name

  • Segment #2 is the controller method to call

Controller Naming Conventions

  • Controllers live in the Picombo::Controllers namespace. They must be prefaced with these modules in the file

  • Controllers are placed in the /controllers directory

  • Controller filenames must be named the same as the class name: class Foobar would live in /controllers/foobar.rb

  • Controller filenames must be lowercase

Controller Arguments

Controller arguments are passed via URI segments after the second, i.e. example.com/foobar/baz/foo/bar

  • This would match the baz method of the foobar controller, and match the arg1 and arg2 method arguments

  • def baz(arg1, arg2)

The arguments must match the method exactly or a 404 exception will occur

Example Controller

module Picombo module Controllers class Foobar def index Picombo::Core.response(‘Hello World!’) end end end end This controller and method could be called via example.com/foobar/index

Defined Under Namespace

Classes: Error_404, Template

Class Method Summary collapse

Class Method Details

.const_missing(name) ⇒ Object

Autoloader for missing controller names

Raises:

  • (LoadError)


290
291
292
293
294
295
296
297
298
299
300
# File 'lib/core/core.rb', line 290

def Controllers.const_missing(name)
	filename = name.to_s

	require 'controllers/'+filename.downcase.gsub(/_/, '/')

	raise LoadError if ! const_defined?(name)

	klass = const_get(name)
	return klass if klass
	raise LoadError
end