Class | Merb::AbstractController |
In: |
lib/merb-core/controller/abstract_controller.rb
|
Parent: | Object |
FILTER_OPTIONS | = | [:only, :exclude, :if, :unless, :with] |
_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 |
Resets the template roots to the template root passed in.
root<~to_s>: | The new path to set the template root to. |
:api: public
roots<Array[Array]>: | Template roots as pairs of template root path and template location method. |
:api: plugin
roots<Array[Array]>: | Template roots as pairs of template root path and template location method. |
:api: plugin
Adds a filter to the after filter chain
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. |
If the filter already exists, its options will be replaced with opts.;
:api: public
Adds a filter to the before filter chain.
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. |
If the filter already exists, its options will be replaced with opts.
:api: public
klass<Merb::AbstractController>: | The controller that is being inherited from Merb::AbstractController |
:api: private
This will initialize the controller, it is designed to be overridden in subclasses (like MerbController)
*args: | The args are ignored in this class, but we need this so that subclassed initializes can have parameters |
:api: private
Returns the list of classes that have specifically subclassed AbstractController. Does not include all decendents.
Set: | The subclasses. |
:api: private
The location to look for a template - override this method for particular behaviour.
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
This method exists to provide an overridable hook for ActionArgs. It uses send to call the action method.
action<~to_s>: | the action method to dispatch to |
:api: plugin @overridable
Determine whether the filter should be called for the current action using :only and :exclude.
rule<Hash>: | Rules for the filter (see below). |
action_name<~to_s>: | The name of the action to be called. |
: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. |
Boolean: | True if the action should be called. |
:api: private
Calls a filter chain.
filter_set<Array[Filter]>: | A set of filters in the form [[:filter, rule], [:filter, rule]] |
Symbol: | :filter_chain_completed. |
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
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.
action<~to_s>: | The action to dispatch to. This will be send‘ed in _call_action. Defaults to :to_s. |
<~to_s>: | Returns the string that was returned from the action. |
ArgumentError: | Invalid result caught from before filters. |
:api: plugin
Evaluates a filter condition (:if or :unless)
condition<Symbol, Proc>: | The condition to evaluate. |
ArgumentError: | condition not a Symbol or Proc. |
Boolean: | True if the condition is met. |
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
Determines whether the filter should be run based on the conditions passed (:if and :unless)
rule<Hash>: | Rules for the filter (see below). |
: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. |
Boolean: | True if the conditions are met. |
:api: private
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.
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 |
String: | Indicating where to look for the template for the current controller, context, and content-type. |
The type is irrelevant for controller-types that don‘t support content-type negotiation, so we default to not include it in the superclass.
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
Calls the concatenate method for the selected template engine.
str<String>: | The string to concatenate to the buffer. |
binding<Binding>: | The binding to use for the buffer. |
:api: public
Generates a URL for a single or nested resource.
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.
String: | The generated URL. |
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
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.
name<Symbol>: | The name of the route. |
args<Hash>: | Parameters for the route generation. |
args<Hash>: | Parameters for the route generation. This route will use the default route. |
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. |
String: | The generated URL. |
Named Route
match("/articles/:title").to(:controller => :articles, :action => :show).name("articles")
end
url(:articles, :title => "new_article")
Default Route
default_routes
end
url(:controller => "articles", :action => "new")
Anonymous Paramters
match("/articles/:year/:month/:title").to(:controller => :articles, :action => :show).name("articles")
end
url(:articles, 2008, 10, "test_article")
:api: public