Class: Merb::AbstractController

Class | Merb::AbstractController
In: | lib/merb-core/controller/abstract_controller.rb
Parent: | Object

### Methods

_absolute_template_location _call_action _call_filter_for_action? _call_filters _dispatch _evaluate_condition _filter_condition_met? _reset_template_roots _template_location _template_root= _template_roots _template_roots= absolute_url after before capture concat controller_name controller_name inherited new relative_url resource skip_after skip_before subclasses_list url

### Included Modules

Merb::RenderMixin Merb::InlineTemplates

### Constants

FILTER_OPTIONS | = | [:only, :exclude, :if, :unless, :with]

### Attributes

_benchmarks | [RW] | :api: plugin
_thrown_content | [RW] | :api: private
action_name | [RW] | :api: plugin
body | [RW] | :api: plugin
content_type | [RW] | Stub so content-type support in RenderMixin doesn‘t throw errors :api: private

### Public Class methods

_reset_template_roots()

Reset the template root based on the @_template_root ivar.

:api: private

_template_root=(root)

Resets the template roots to the template root passed in.

#### Parameters

root<~to_s>: | The new path to set the template root to.

:api: public

_template_roots()

#### Returns

roots<Array[Array]>: | Template roots as pairs of template root path and template location method.

:api: plugin

_template_roots=(roots)

#### Parameters

roots<Array[Array]>: | Template roots as pairs of template root path and template location method.

:api: plugin

after(filter = nil, opts = {}, &block)

Adds a filter to the after filter chain

#### Parameters

filter<Symbol, Proc>: | The filter to add. Defaults to nil.
opts<Hash>: | Filter options (see class documentation under `Filter Options`).
&block: | A block to use as a filter if filter is nil.

#### Notes

If the filter already exists, its options will be replaced with opts.;

:api: public

before(filter = nil, opts = {}, &block)

Adds a filter to the before filter chain.

#### Parameters

filter<Symbol, Proc>: | The filter to add. Defaults to nil.
opts<Hash>: | Filter options (see class documentation under `Filter Options`).
&block: | A block to use as a filter if filter is nil.

#### Notes

If the filter already exists, its options will be replaced with opts.

:api: public

controller_name()

#### Returns

String: | The controller name in path form, e.g. "admin/items".

:api: public

inherited(klass)

#### Parameters

klass<Merb::AbstractController>: | The controller that is being inherited from Merb::AbstractController

:api: private

new(*args)

This will initialize the controller, it is designed to be overridden in subclasses (like MerbController)

#### Parameters

*args: | The args are ignored in this class, but we need this so that subclassed initializes can have parameters

:api: private

skip_after(filter)

Removes a filter from the after filter chain. This removes the filter from the filter chain for the whole controller and does not take any options.

#### Parameters

filter<Symbol, String>: | A filter name to skip.

:api: public

skip_before(filter)

Removes a filter from the before filter chain. This removes the filter from the filter chain for the whole controller and does not take any options.

#### Parameters

filter<Symbol, String>: | A filter name to skip.

:api: public

subclasses_list()

Returns the list of classes that have specifically subclassed AbstractController. Does not include all decendents.

#### Returns

Set: | The subclasses.

:api: private

### Public Instance methods

_absolute_template_location(template, type)

The location to look for a template - override this method for particular behaviour.

#### Parameters

template<String>: | The absolute path to a template - without template extension.
type<~to_s>: | The mime-type of the template that will be rendered. Defaults to being called with nil.

:api: public @overridable

_call_action(action)

This method exists to provide an overridable hook for ActionArgs. It uses send to call the action method.

#### Parameters

action<~to_s>: | the action method to dispatch to

:api: plugin @overridable

_call_filter_for_action?(rule, action_name)

Determine whether the filter should be called for the current action using :only and :exclude.

#### Parameters

rule<Hash>: | Rules for the filter (see below).
action_name<~to_s>: | The name of the action to be called.

#### Options (rule)

:only<Array>: | Optional list of actions to fire. If given, action_name must be a part of it for this function to return true.
:exclude<Array>: | Optional list of actions not to fire. If given, action_name must not be a part of it for this function to return true.

#### Returns

Boolean: | True if the action should be called.

:api: private

_call_filters(filter_set)

Calls a filter chain.

#### Parameters

filter_set<Array[Filter]>: | A set of filters in the form [[:filter, rule], [:filter, rule]]

#### Returns

Symbol: | :filter_chain_completed.

#### Notes

Filter rules can be Symbols, Strings, or Procs.

Symbols or Strings: | Call the method represented by the `Symbol` or `String`.
Procs: | Execute the `Proc`, in the context of the controller (self will be the controller)

:api: private

_dispatch(action)

This will dispatch the request, calling internal before/after dispatch callbacks. If the return value of _call_filters is not :filter_chain_completed the action is not called, and the return from the filters is used instead.

#### Parameters

action<~to_s>: | The action to dispatch to. This will be send‘ed in _call_action. Defaults to :to_s.

#### Returns

<~to_s>: | Returns the string that was returned from the action.

#### Raises

ArgumentError: | Invalid result caught from before filters.

:api: plugin

_evaluate_condition(condition)

Evaluates a filter condition (:if or :unless)

#### Parameters

condition<Symbol, Proc>: | The condition to evaluate.

#### Raises

ArgumentError: | condition not a Symbol or Proc.

#### Returns

Boolean: | True if the condition is met.

#### Alternatives

If condition is a symbol, it will be send‘ed. If it is a Proc it will be called directly with self as an argument.

:api: private

_filter_condition_met?(rule)

Determines whether the filter should be run based on the conditions passed (:if and :unless)

#### Parameters

rule<Hash>: | Rules for the filter (see below).

#### Options (rule)

:if<Array>: | Optional conditions that must be met for the filter to fire.
:unless<Array>: | Optional conditions that must not be met for the filter to fire.

#### Returns

Boolean: | True if the conditions are met.

:api: private

_template_location(context, type, controller)

This is called after the controller is instantiated to figure out where to look for templates under the _template_root. Override this to define a new structure for your app.

#### Parameters

context<~to_s>: | The controller context (the action or template name).
type<~to_s>: | The content type. Could be nil.
controller<~to_s>: | The name of the controller. Defaults to being called with the controller_name. Set t

#### Returns

String: | Indicating where to look for the template for the current controller, context, and content-type.

#### Notes

The type is irrelevant for controller-types that don‘t support content-type negotiation, so we default to not include it in the superclass.

#### Examples

      def _template_location
        "#{params[:controller]}.#{params[:action]}.#{content_type}"
      end

This would look for templates at controller.action.mime.type instead of controller/action.mime.type

:api: public @overridable

absolute_url(*args)

Returns the absolute url including the passed protocol and host.

This uses the same arguments as the url method, with added requirements of protocol and host options.

:api: public

capture(*args) {|*args| ...}

Calls the capture method for the selected template engine.

#### Parameters

*args: | Arguments to pass to the block.
&block: | The block to call.

#### Returns

String: | The output of a template block or the return value of a non-template block converted to a string.

:api: public

concat(str, binding)

Calls the concatenate method for the selected template engine.

#### Parameters

str<String>: | The string to concatenate to the buffer.
binding<Binding>: | The binding to use for the buffer.

:api: public

controller_name()

#### Returns

String: | The controller name in path form, e.g. "admin/items".

:api: public

relative_url(name, *args)

Alias for url

resource(*args)

Generates a URL for a single or nested resource.

#### Parameters

resources<Symbol,Object>: | The resources for which the URL

      should be generated. These resources should be specified
      in the router.rb file using #resources and #resource.

options<Hash>: | Any extra parameters that are needed to

      generate the URL.

#### Returns

String: | The generated URL.

#### Examples

Merb::Router.prepare do

      resources :users do
        resources :comments
      end

end

resource(:users) # => /users resource(@user) # => /users/10 resource(@user, :comments) # => /users/10/comments resource(@user, @comment) # => /users/10/comments/15 resource(:users, :new) # => /users/new resource(:@user, :edit) # => /users/10/edit

:api: public

url(name, *args)

There are three possible ways to use this method. First, if you have a named route, you can specify the route as the first parameter as a symbol and any paramters in a hash. Second, you can generate the default route by just passing the params hash, just passing the params hash. Finally, you can use the anonymous parameters. This allows you to specify the parameters to a named route in the order they appear in the router.

#### Parameters(Named Route)

name<Symbol>: | The name of the route.
args<Hash>: | Parameters for the route generation.

#### Parameters(Default Route)

args<Hash>: | Parameters for the route generation. This route will use the default route.

#### Parameters(Anonymous Parameters)

name<Symbol>: | The name of the route.
args<Array>: | An array of anonymous parameters to generate the route with. These parameters are assigned to the route parameters in the order that they are passed.

#### Returns

String: | The generated URL.

#### Examples

Named Route

Merb::Router.prepare do

      match("/articles/:title").to(:controller => :articles, :action => :show).name("articles")

end

url(:articles, :title => "new_article")

Default Route

Merb::Router.prepare do

      default_routes

end

url(:controller => "articles", :action => "new")

Anonymous Paramters

Merb::Router.prepare do

      match("/articles/:year/:month/:title").to(:controller => :articles, :action => :show).name("articles")

end

url(:articles, 2008, 10, "test_article")

:api: public

[Validate]