Class | Merb::Controller |
In: |
lib/merb-core/controller/merb_controller.rb
|
Parent: | Merb::AbstractController |
headers | [R] | :api: public |
request | [R] | :api: public |
All methods that are callable as actions.
Array: | A list of method names that are also actions |
:api: private
Sets a controller to be "abstract" This controller will not be able to be routed to and is used for super classing only
:api: public
Asks a controller if it is abstract
Boolean
true if the controller has been set as abstract
:api: public
Call the controller as a Rack endpoint.
Expects:
env["merb.status"]:: the default status code to be returned env["merb.action_name"]:: the action name to dispatch env["merb.request_start"]:: a Time object representing the start of the request.
env<Hash>: | A rack environment |
Array[Integer, Hash, each]: | A standard Rack response |
:api: public
The list of actions that are callable, after taking defaults, _hidden_actions and _shown_actions into consideration. It is calculated once, the first time an action is dispatched for this controller.
SimpleSet[String]: | A set of actions that should be callable. |
:api: public
Hide each of the given methods from being callable as actions.
*names<~to-s>: | Actions that should be added to the list. |
Array[String]: | An array of actions that should not be possible to dispatch to. |
:api: public
klass<Merb::Controller>: | The Merb::Controller inheriting from the base class. |
:api: private
Build a new controller.
Sets the variables that came in through the dispatch as available to the controller.
request<Merb::Request>: | The Merb::Request that came in from Rack. |
status<Integer>: | An integer code for the status. Defaults to 200. |
headers<Hash{header => value}>: | A hash of headers to start the controller with. These headers can be overridden later by the headers method. |
:api: plugin @overridable
*names<Array[Symbol]>: | an Array of method names that should be overridable in application controllers. |
Array: | The list of methods that are overridable |
:api: plugin
In an application controller, call override! before a method to indicate that you want to override a method in Merb::Controller that is not normally overridable.
Doing this may potentially break your app in a future release of Merb, and this is provided for users who are willing to take that risk. Without using override!, Merb will raise an error if you attempt to override a method defined on Merb::Controller.
This is to help users avoid a common mistake of defining an action that overrides a core method on Merb::Controller.
*names<Array[Symbol]>: | An Array of methods that will override Merb core classes on purpose |
class Kontroller < Application def status render end end
will raise a Merb::ReservedError, because status is a method on Merb::Controller.
class Kontroller < Application override! :status def status some_code || super end end
will not raise a Merb::ReservedError, because the user specifically decided to override the status method.
:api: public
Makes each of the given methods being callable as actions. You can use this to make methods included from modules callable as actions.
*names<~to-s>: | Actions that should be added to the list. |
Array[String]: | An array of actions that should be dispatched to even if they would not otherwise be. |
module Foo def self.included(base) base.show_action(:foo) end def foo # some actiony stuff end def foo_helper # this should not be an action end end
:api: public
The location to look for a template and mime-type. This is overridden from AbstractController, which defines a version of this that does not involve mime-types.
template<String>: | The absolute path to a template - without mime and template extension. The mime-type extension is optional - it will be appended from the current content type if it hasn‘t been added already. |
type<~to_s>: | The mime-type of the template that will be rendered. Defaults to nil. |
:api: public
Dispatch the action.
action<~to_s>: | An action to dispatch to. Defaults to :index. |
String: | The string sent to the logger for time spent. |
ActionNotFound: | The requested action was not found in class. |
:api: plugin
The location to look for a template for a particular controller, context, and mime-type. This is overridden from AbstractController, which defines a version of this that does not involve mime-types.
context<~to_s>: | The name of the action or template basename that will be rendered. |
type<~to_s>: | The mime-type of the template that will be rendered. Defaults to nil. |
controller<~to_s>: | The name of the controller that will be rendered. Defaults to controller_name. This will be "layout" for rendering a layout. |
By default, this renders ":controller/:action.:type". To change this, override it in your application class or in individual controllers.
:api: public @overridable
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