Init lifecycle and rails

In a servlet J2EE application, there is an init style method that gets
called after that servlet is loaded. Is there something similar within
a rails controller context. I am looking for something where I can load
and setup a particular object.

Also, what about with sessions as well. I would like to call some
library when a user session begins and possibly kill that object when
the session ends.


Berlin B.
(ramaza3 on freenode)
http://www.newspiritcompany.com
http://www.newspiritcompany.com/newforums
also checkout alpha version of botverse:
http://www.newspiritcompany.com:8086/universe_home

On 5/29/06, Berlin B. [email protected] wrote:

In a servlet J2EE application, there is an init style method that gets
called after that servlet is loaded. Is there something similar within
a rails controller context. I am looking for something where I can load
and setup a particular object.

Perhaps you want a before_filter?

http://api.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html#M000150

Also, what about with sessions as well. I would like to call some
library when a user session begins and possibly kill that object when
the session ends.

Sessions are usually automatically created on Rails, by default, upon
first access. So it seems doubtful that there is a special callback,
since they are “nothing special”. However, you can easily setup a
global method (through ApplicationController) that would
setup/teardown session, something like start_session/end_session.