All of your web controllers will inherit from Merb::Controller. This superclass takes care of parsing the incoming headers and body into params and cookies and headers. If the request is a file upload it will stream it into a tempfile and pass in the filename and tempfile object to your controller via params. It also parses the ?query=string and puts that into params as well.

Sessions

Session data can be accessed through the session hash:

session[:user_id] = @user.id

Session data is available until the user’s cookie gets deleted/expires, or until your specific session store expires the data.

Session Store

The session store is set in Merb.root/config/merb.yml :

:session_store: your_store

Out of the box merb supports three session stores

cookie:All data (max 4kb) stored directly in cookie. Data integrity is checked on each request to prevent tampering. (Merb::CookieStore)
memory:Data stored in a class in memory. (Merb::MemorySession)
mem_cache:Data stored in mem_cache. (Merb::MemCacheSession)

See the documentation on each session store for more information.

You can also use a session store provided by a plugin. For instance, if you have DataMapper you can set

:session_store: datamapper

In this case session data will be stored in the database, as defined by the merb_datamapper plugin. Similar functionality exists for activerecord and sequel currently.

Public Methods
body Accessor for @_body. Please use body and never @body directly.
build
callable_actions
cookies
dispatch
headers Accessor for @_headers. Please use headers and never @_headers directly.
hidden_actions
hide_action Hide each of the given methods from being callable as actions.
inherited
params
part Dispatches a PartController. Use like:
request Accessor for @_request. Please use request and never @_request directly.
response Accessor for @_response. Please use response and never @_response directly.
route Accessor for @_route. Please use route and never @_route directly.
send_mail Sends mail via a MailController (a tutorial can be found in the MailController docs).
session Accessor for @_session. Please use session and never @_session directly.
set_dispatch_variables
status Accessor for @_status. Please use status and never @_status directly.
Private Methods
get_controller_for_url_generation This method is here to overwrite the one in the general_controller mixin The method ensures that when a url is generated with a hash, it contains a controller
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.