### Home Classes Methods

### In Files

- lib/ramaze/controller.rb

### Parent

Object

### Methods

- ::app
- ::engine
- ::generate_mapping
- ::inherited
- ::map
- ::mapping
- ::options
- ::setup
- ::setup_procedure

### Included Modules

- Innate::Traited
- Innate::Node

### Class/Module Index

Quicksearch

- Ramaze
- Ramaze::App
- Ramaze::AppGraph
- Ramaze::Bin
- Ramaze::Bin::Console
- Ramaze::Bin::Create
- Ramaze::Bin::Helper
- Ramaze::Bin::Restart
- Ramaze::Bin::Runner
- Ramaze::Bin::Start
- Ramaze::Bin::Status
- Ramaze::Bin::Stop
- Ramaze::Cache
- Ramaze::Cache::LRU
- Ramaze::Cache::LocalMemCache
- Ramaze::Cache::MemCache
- Ramaze::Cache::Redis
- Ramaze::Cache::Sequel
- Ramaze::Controller
- Ramaze::CoreExtensions
- Ramaze::CoreExtensions::Array
- Ramaze::CoreExtensions::Binding
- Ramaze::CoreExtensions::Kernel
- Ramaze::CoreExtensions::Numeric
- Ramaze::CoreExtensions::Object
- Ramaze::CoreExtensions::Proc
- Ramaze::CoreExtensions::String
- Ramaze::Current
- Ramaze::DefaultController
- Ramaze::Dictionary
- Ramaze::Fiber
- Ramaze::Files
- Ramaze::GemSetup
- Ramaze::Gestalt
- Ramaze::Helper
- Ramaze::Helper::Auth
- Ramaze::Helper::Bench
- Ramaze::Helper::BlueForm
- Ramaze::Helper::BlueForm::Form
- Ramaze::Helper::CSRF
- Ramaze::Helper::Cache
- Ramaze::Helper::Cache::SingletonMethods
- Ramaze::Helper::Disqus
- Ramaze::Helper::Email
- Ramaze::Helper::Erector
- Ramaze::Helper::Flash
- Ramaze::Helper::Formatting
- Ramaze::Helper::Gestalt
- Ramaze::Helper::Gravatar
- Ramaze::Helper::Identity
- Ramaze::Helper::Layout
- Ramaze::Helper::Layout::SingletonMethods
- Ramaze::Helper::Link
- Ramaze::Helper::Localize
- Ramaze::Helper::Localize::Dictionary
- Ramaze::Helper::Localize::Parser
- Ramaze::Helper::Markaby
- Ramaze::Helper::Maruku
- Ramaze::Helper::Paginate
- Ramaze::Helper::Paginate::Paginator
- Ramaze::Helper::Paginate::Paginator::ArrayPager
- Ramaze::Helper::Paginate::Paginator::DataMapperPager
- Ramaze::Helper::Remarkably
- Ramaze::Helper::RequestAccessor
- Ramaze::Helper::SendFile
- Ramaze::Helper::SimpleCaptcha
- Ramaze::Helper::Stack
- Ramaze::Helper::Thread
- Ramaze::Helper::Ultraviolet
- Ramaze::Helper::Upload
- Ramaze::Helper::Upload::ClassMethods
- Ramaze::Helper::Upload::UploadedFile
- Ramaze::Helper::UserHelper
- Ramaze::Helper::UserHelper::Wrapper
- Ramaze::Helper::XHTML
- Ramaze::LRUHash
- Ramaze::Logger
- Ramaze::Logger::Analogger
- Ramaze::Logger::Growl
- Ramaze::Logger::Informer
- Ramaze::Logger::Knotify
- Ramaze::Logger::LogHub
- Ramaze::Logger::Logger
- Ramaze::Logger::RotatingInformer
- Ramaze::Logger::Syslog
- Ramaze::Logger::Xosd
- Ramaze::Logging
- Ramaze::MiddlewareCompiler
- Ramaze::Plugin
- Ramaze::Reloader
- Ramaze::Reloader::Hooks
- Ramaze::Reloader::WatchInotify
- Ramaze::Reloader::WatchStat
- Ramaze::Reloader::Watcher
- Ramaze::Request
- Ramaze::Response
- Ramaze::SpecLogger
- Ramaze::Struct
- Ramaze::View
- Ramaze::View::Erector
- Ramaze::View::Erubis
- Ramaze::View::Ezamar
- Ramaze::View::Gestalt
- Ramaze::View::Haml
- Ramaze::View::Liquid
- Ramaze::View::Liquid::Tag
- Ramaze::View::Lokar
- Ramaze::View::Mustache
- Ramaze::View::Mustache::RamazeContext
- Ramaze::View::Nagoro
- Ramaze::View::Remarkably
- Ramaze::View::Sass
- Ramaze::View::Slippers
- Ramaze::View::Tagz
- Ramaze::View::Tagz::Methods
- Ramaze::View::Tenjin
- Nagoro
- Nagoro::Pipe
- Nagoro::Pipe::RenderPartial
- Bacon
- Bacon::PrettyOutput
- Erector
- Erector::Widget
- Rack
- Rack::RouteExceptions
- Tenjin
- Tenjin::Template
- BlankSlate
- Controller
- Fiber
- FiberError
- MainController
- Object
- OrderedSet
- Thread

No matching classes.

# Ramaze::Controller

Ramaze::Controller is the base controller of all controllers when developing applications in Ramaze. It acts as a nice wrapper around Innate::Node and allows for a more traditional MVC approach.

@example An example controller

    class Posts < Ramaze::Controller
      map '/posts'

      def index

      end
    end

@author Michael Fellinger @since 04-01-2009

### Constants

CONTROLLER_LIST
IRREGULAR_MAPPING

  Hash containing the names of two common controller names and the URIs they should be mapped to.

  @author Michael Fellinger @since 04-01-2009

### Public Class Methods

app() click to toggle source

Returns the application to which the controller belongs to.

@author Michael Fellinger @since 04-01-2009 @return [Ramaze::App]

    # File lib/ramaze/controller.rb, line 185
    def self.app
      App[ancestral_trait[:app]]
    end

engine(name) click to toggle source

Sets the view engine to use for pages with a content type of text/html.

@example

    class Posts < Ramaze::Controller
      engine :etanni
    end

@author Michael Fellinger @since 04-01-2009 @param [to_sym] name The name of the view engine to use.

    # File lib/ramaze/controller.rb, line 121
    def self.engine(name)
      provide(:html, name.to_sym)
    end

generate_mapping(klass_name = self.name) click to toggle source

Generates a URI for the full namespace of a class. If a class is named A::B::C the URI would be /a/b/c.

@author Michael Fellinger @since 04-01-2009 @param [String] klass_name The name of the class for which to generate

    the mapping, defaults to the current class.

@return [String]

    # File lib/ramaze/controller.rb, line 146
    def self.generate_mapping(klass_name = self.name)
      chunks = klass_name.to_s.split(/::/)
      return if chunks.empty?

      last = chunks.last
      return IRREGULAR_MAPPING[last] if IRREGULAR_MAPPING.key?(last)

      last.sub!(/Controller$/, '')
      '/' << chunks.map{|chunk| chunk.snake_case }.join('/')
    end

inherited(into) click to toggle source

Modifies the extending class so that it's properly set up to be used as a controller.

@author Michael Fellinger @since 04-01-2009 @param [Class] into The class that extended Ramaze::Controller (or a sub

    class).

    # File lib/ramaze/controller.rb, line 58
    def self.inherited(into)
      Innate::Node.included(into)
      into.helper(:layout)
      CONTROLLER_LIST << into
      into.trait :skip_node_map => true
    end

map(location, app_name = nil) click to toggle source

Maps the current class to the specified location.

@author Michael Fellinger @since 04-01-2009 @param [String] location The URI to map the controller to. @param [String] app_name The name of the application the controller

    belongs to.

    # File lib/ramaze/controller.rb, line 166
    def self.map(location, app_name = nil)
      if app_name
        trait :app => app_name
      else
        app_name = ancestral_trait[:app]
      end

      trait :skip_controller_map => true

      App.find_or_create(app_name).map(location, self)
    end

mapping() click to toggle source

Returns the URI a controller is mapped to.

@author Michael Fellinger @since 04-01-2009 @return [String]

    # File lib/ramaze/controller.rb, line 132
    def self.mapping
      Ramaze.to(self)
    end

options() click to toggle source

Returns all the options for the application the controller belongs to.

@author Michael Fellinger @since 04-01-2009 @return [Innate::Options]

    # File lib/ramaze/controller.rb, line 196
    def self.options
      return unless app = self.app
      app.options
    end

setup() click to toggle source

Sets all the controllers up and loads a default controller in case no custom ones have been specified.

@author Michael Fellinger @since 04-01-2009

    # File lib/ramaze/controller.rb, line 72
    def self.setup
      case CONTROLLER_LIST.size
      when 0
        require 'ramaze/controller/default'
      when 1
        controller = CONTROLLER_LIST.to_a.first

        begin
          controller.mapping
        rescue
          controller.map '/'
        end

        controller.setup_procedure
      else
        CONTROLLER_LIST.each do |controller|
          controller.setup_procedure
        end
      end
    end

setup_procedure() click to toggle source

Method that's used to setup each controller, called by Ramaze::Controller.setup.

@author Michael Fellinger @since 04-01-2009

    # File lib/ramaze/controller.rb, line 100
    def self.setup_procedure
      unless ancestral_trait[:provide_set]
        engine(:etanni)
        trait(:provide_set => false)
      end

      map(generate_mapping(name)) unless trait[:skip_controller_map]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.