Hi, In my test case below, it seems that ''initialize'' is called everytime ''hello'' is called. Is this by design, a bug, or my pilot error? class FooController < ApplicationController def initialize print "\n initialize \n" end def hello print "\n hello \n" end end I thought initialize will be called exactly once when the controller is constructed and not when an action is executed. Thanks for your help and sorry if duplicate, -Danny
On 12/15/05, Danny Hendargo <danny-uFU5qH6teA8qcZcGjlUOXw@public.gmane.org> wrote:> Hi, > > In my test case below, it seems that ''initialize'' is called everytime > ''hello'' is called. Is this by design, a bug, or my pilot error? > > class FooController < ApplicationController > > def initialize > print "\n initialize \n" > end > > def hello > print "\n hello \n" > end > end > > I thought initialize will be called exactly once when the controller is > constructed and not when an action is executed.On every request, a controller object is created. When the controller object is created, the initialized function is called.
Well the controler gets created every time a action is called, HTTP is a stateless protocol : ) Danny Hendargo wrote:> Hi, > > In my test case below, it seems that ''initialize'' is called everytime > ''hello'' is called. Is this by design, a bug, or my pilot error? > > class FooController < ApplicationController > > def initialize > print "\n initialize \n" > end > > def hello > print "\n hello \n" > end > end > > I thought initialize will be called exactly once when the controller > is constructed and not when an action is executed. > > Thanks for your help and sorry if duplicate, > > -Danny > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Thu, 2005-12-15 at 15:47 -0800, Danny Hendargo wrote:> Hi, > > In my test case below, it seems that ''initialize'' is called everytime > ''hello'' is called. Is this by design, a bug, or my pilot error? > > class FooController < ApplicationController > > def initialize > print "\n initialize \n" > end > > def hello > print "\n hello \n" > end > end > > I thought initialize will be called exactly once when the controller is > constructed and not when an action is executed.This is correct, it''s just that a new FooController is being created (instantiated, whatever) for each request. - Jamie
If you''re in dev mode, I believe the controller would be reloaded with every request so you would see initialize called for each invocation of hello. On Dec 15, 2005, at 5:47 PM, Danny Hendargo wrote:> Hi, > > In my test case below, it seems that ''initialize'' is called > everytime ''hello'' is called. Is this by design, a bug, or my pilot > error? > > class FooController < ApplicationController > > def initialize > print "\n initialize \n" > end > > def hello > print "\n hello \n" > end > end > > I thought initialize will be called exactly once when the > controller is constructed and not when an action is executed. > > Thanks for your help and sorry if duplicate, > > -Danny > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
On 12/15/05, Steven Smith <ssmith-ykxUa7oIpO9Wk0Htik3J/w@public.gmane.org> wrote:> If you''re in dev mode, I believe the controller would be reloaded > with every request so you would see initialize called for each > invocation of hello.Controllers get re-constructed on every invocation of every action, no matter if you''re in development, test, or production mode.> On Dec 15, 2005, at 5:47 PM, Danny Hendargo wrote: > > > Hi, > > > > In my test case below, it seems that ''initialize'' is called > > everytime ''hello'' is called. Is this by design, a bug, or my pilot > > error? > > > > class FooController < ApplicationController > > > > def initialize > > print "\n initialize \n" > > end > > > > def hello > > print "\n hello \n" > > end > > end > > > > I thought initialize will be called exactly once when the > > controller is constructed and not when an action is executed. > > > > Thanks for your help and sorry if duplicate, > > > > -Danny > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Apparently Analagous Threads
- Webrick is being stupid...no info on a brand new project
- rspec_on_rails: controller method not getting called
- (BUG in svn/trunk?) - superclass mismatch for any subclass of ApplicationController
- Using idmap_rid backend, cannot browse home directory from XP
- reloading include-modules inside controller not working