Hi all, A little question. How can u use an constructor in controller? I would like to initialize some central stuff before i''m processing the controller. thanks in advance, Martijn
Martijn van Leeuwen wrote:> Hi all, > > A little question. How can u use an constructor in controller? I would > like to initialize some central stuff before i''m processing the controller.Use a before_filter. -- Alex
You probably actually want to use a before_filter to perform some initialization before performing an action, rather than use a constructor at all... unless you have some very odd requirements. - james On 1/24/06, Martijn van Leeuwen <ruby@martijnvanleeuwen.nl> wrote:> Hi all, > > A little question. How can u use an constructor in controller? I would > like to initialize some central stuff before i''m processing the controller. > > thanks in advance, > > Martijn > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 1/24/06, James Adam <james.adam@gmail.com> wrote:> You probably actually want to use a before_filter to perform some > initialization before performing an action, rather than use a > constructor at all... unless you have some very odd requirements.I don''t understand Rails internals at at all... so I''m curious. Why wouldn''t a constructor with a call to super work? Joe> On 1/24/06, Martijn van Leeuwen <ruby@martijnvanleeuwen.nl> wrote: > > Hi all, > > > > A little question. How can u use an constructor in controller? I would > > like to initialize some central stuff before i''m processing the controller. > > > > thanks in advance, > > > > Martijn > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I''m not sure about controllers, but I found the hard way that Rails disconnects model initialize methods for performance purposes... Perhaps the controllers are the same? -- -- Tom Mornini On Jan 24, 2006, at 10:32 AM, Joe Van Dyk wrote:> On 1/24/06, James Adam <james.adam@gmail.com> wrote: >> You probably actually want to use a before_filter to perform some >> initialization before performing an action, rather than use a >> constructor at all... unless you have some very odd requirements. > > I don''t understand Rails internals at at all... so I''m curious. > > Why wouldn''t a constructor with a call to super work? > > Joe > >> On 1/24/06, Martijn van Leeuwen <ruby@martijnvanleeuwen.nl> wrote: >>> Hi all, >>> >>> A little question. How can u use an constructor in controller? I >>> would >>> like to initialize some central stuff before i''m processing the >>> controller. >>> >>> thanks in advance, >>> >>> Martijn >>> >>> _______________________________________________ >>> Rails mailing list >>> Rails@lists.rubyonrails.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Constructor objects are actually created as part of the dispatcher process (dispatcher.rb, around line 38): ActionController::Routing::Routes.recognize!(request).process(request, response).out(output) Basically, deep within the routing system the code generation performed by routing instantiates the relevant ApplicationController subclass (that call to recognize!() returns it, as I recall), and it needs to have control over which arguments are given. Joo don'' wanna mess wit dat. - james On 1/24/06, Tom Mornini <tmornini@infomania.com> wrote:> I''m not sure about controllers, but I found the hard way that Rails > disconnects model initialize methods for performance purposes... > > Perhaps the controllers are the same? > > -- > -- Tom Mornini > > > On Jan 24, 2006, at 10:32 AM, Joe Van Dyk wrote: > > > On 1/24/06, James Adam <james.adam@gmail.com> wrote: > >> You probably actually want to use a before_filter to perform some > >> initialization before performing an action, rather than use a > >> constructor at all... unless you have some very odd requirements. > > > > I don''t understand Rails internals at at all... so I''m curious. > > > > Why wouldn''t a constructor with a call to super work? > > > > Joe > > > >> On 1/24/06, Martijn van Leeuwen <ruby@martijnvanleeuwen.nl> wrote: > >>> Hi all, > >>> > >>> A little question. How can u use an constructor in controller? I > >>> would > >>> like to initialize some central stuff before i''m processing the > >>> controller. > >>> > >>> thanks in advance, > >>> > >>> Martijn > >>> > >>> _______________________________________________ > >>> Rails mailing list > >>> Rails@lists.rubyonrails.org > >>> http://lists.rubyonrails.org/mailman/listinfo/rails > >>> > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 1/25/06, James Adam <james.adam@gmail.com> wrote:> Constructor objects are actually created as part of the dispatcher > process (dispatcher.rb, around line 38):Do you mean "Controller objects"? Joe> ActionController::Routing::Routes.recognize!(request).process(request, > response).out(output) > > Basically, deep within the routing system the code generation > performed by routing instantiates the relevant ApplicationController > subclass (that call to recognize!() returns it, as I recall), and it > needs to have control over which arguments are given. Joo don'' wanna > mess wit dat. > > - james > > On 1/24/06, Tom Mornini <tmornini@infomania.com> wrote: > > I''m not sure about controllers, but I found the hard way that Rails > > disconnects model initialize methods for performance purposes... > > > > Perhaps the controllers are the same? > > > > -- > > -- Tom Mornini > > > > > > On Jan 24, 2006, at 10:32 AM, Joe Van Dyk wrote: > > > > > On 1/24/06, James Adam <james.adam@gmail.com> wrote: > > >> You probably actually want to use a before_filter to perform some > > >> initialization before performing an action, rather than use a > > >> constructor at all... unless you have some very odd requirements. > > > > > > I don''t understand Rails internals at at all... so I''m curious. > > > > > > Why wouldn''t a constructor with a call to super work? > > > > > > Joe > > > > > >> On 1/24/06, Martijn van Leeuwen <ruby@martijnvanleeuwen.nl> wrote: > > >>> Hi all, > > >>> > > >>> A little question. How can u use an constructor in controller? I > > >>> would > > >>> like to initialize some central stuff before i''m processing the > > >>> controller. > > >>> > > >>> thanks in advance, > > >>> > > >>> Martijn > > >>> > > >>> _______________________________________________ > > >>> Rails mailing list > > >>> Rails@lists.rubyonrails.org > > >>> http://lists.rubyonrails.org/mailman/listinfo/rails > > >>> > > >> _______________________________________________ > > >> Rails mailing list > > >> Rails@lists.rubyonrails.org > > >> http://lists.rubyonrails.org/mailman/listinfo/rails > > >> > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Yes - d''oh! :) On 1/25/06, Joe Van Dyk <joevandyk@gmail.com> wrote:> On 1/25/06, James Adam <james.adam@gmail.com> wrote: > > Constructor objects are actually created as part of the dispatcher > > process (dispatcher.rb, around line 38): > > Do you mean "Controller objects"? > > Joe > > > ActionController::Routing::Routes.recognize!(request).process(request, > > response).out(output) > > > > Basically, deep within the routing system the code generation > > performed by routing instantiates the relevant ApplicationController > > subclass (that call to recognize!() returns it, as I recall), and it > > needs to have control over which arguments are given. Joo don'' wanna > > mess wit dat. > > > > - james > > > > On 1/24/06, Tom Mornini <tmornini@infomania.com> wrote: > > > I''m not sure about controllers, but I found the hard way that Rails > > > disconnects model initialize methods for performance purposes... > > > > > > Perhaps the controllers are the same? > > > > > > -- > > > -- Tom Mornini > > > > > > > > > On Jan 24, 2006, at 10:32 AM, Joe Van Dyk wrote: > > > > > > > On 1/24/06, James Adam <james.adam@gmail.com> wrote: > > > >> You probably actually want to use a before_filter to perform some > > > >> initialization before performing an action, rather than use a > > > >> constructor at all... unless you have some very odd requirements. > > > > > > > > I don''t understand Rails internals at at all... so I''m curious. > > > > > > > > Why wouldn''t a constructor with a call to super work? > > > > > > > > Joe > > > > > > > >> On 1/24/06, Martijn van Leeuwen <ruby@martijnvanleeuwen.nl> wrote: > > > >>> Hi all, > > > >>> > > > >>> A little question. How can u use an constructor in controller? I > > > >>> would > > > >>> like to initialize some central stuff before i''m processing the > > > >>> controller. > > > >>> > > > >>> thanks in advance, > > > >>> > > > >>> Martijn > > > >>> > > > >>> _______________________________________________ > > > >>> Rails mailing list > > > >>> Rails@lists.rubyonrails.org > > > >>> http://lists.rubyonrails.org/mailman/listinfo/rails > > > >>> > > > >> _______________________________________________ > > > >> Rails mailing list > > > >> Rails@lists.rubyonrails.org > > > >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > >> > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails@lists.rubyonrails.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 1/25/06, James Adam <james.adam@gmail.com> wrote:> Yes - d''oh! :)I hope David Black''s upcoming Rails book will illuminate this Rails voodoo to me. I understand Ruby fairly well, but the Rails internals are still magic.> On 1/25/06, Joe Van Dyk <joevandyk@gmail.com> wrote: > > On 1/25/06, James Adam <james.adam@gmail.com> wrote: > > > Constructor objects are actually created as part of the dispatcher > > > process (dispatcher.rb, around line 38): > > > > Do you mean "Controller objects"? > > > > Joe > > > > > ActionController::Routing::Routes.recognize!(request).process(request, > > > response).out(output) > > > > > > Basically, deep within the routing system the code generation > > > performed by routing instantiates the relevant ApplicationController > > > subclass (that call to recognize!() returns it, as I recall), and it > > > needs to have control over which arguments are given. Joo don'' wanna > > > mess wit dat. > > > > > > - james > > > > > > On 1/24/06, Tom Mornini <tmornini@infomania.com> wrote: > > > > I''m not sure about controllers, but I found the hard way that Rails > > > > disconnects model initialize methods for performance purposes... > > > > > > > > Perhaps the controllers are the same? > > > > > > > > -- > > > > -- Tom Mornini > > > > > > > > > > > > On Jan 24, 2006, at 10:32 AM, Joe Van Dyk wrote: > > > > > > > > > On 1/24/06, James Adam <james.adam@gmail.com> wrote: > > > > >> You probably actually want to use a before_filter to perform some > > > > >> initialization before performing an action, rather than use a > > > > >> constructor at all... unless you have some very odd requirements. > > > > > > > > > > I don''t understand Rails internals at at all... so I''m curious. > > > > > > > > > > Why wouldn''t a constructor with a call to super work? > > > > > > > > > > Joe > > > > > > > > > >> On 1/24/06, Martijn van Leeuwen <ruby@martijnvanleeuwen.nl> wrote: > > > > >>> Hi all, > > > > >>> > > > > >>> A little question. How can u use an constructor in controller? I > > > > >>> would > > > > >>> like to initialize some central stuff before i''m processing the > > > > >>> controller. > > > > >>> > > > > >>> thanks in advance, > > > > >>> > > > > >>> Martijn > > > > >>> > > > > >>> _______________________________________________ > > > > >>> Rails mailing list > > > > >>> Rails@lists.rubyonrails.org > > > > >>> http://lists.rubyonrails.org/mailman/listinfo/rails > > > > >>> > > > > >> _______________________________________________ > > > > >> Rails mailing list > > > > >> Rails@lists.rubyonrails.org > > > > >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > > >> > > > > > _______________________________________________ > > > > > Rails mailing list > > > > > Rails@lists.rubyonrails.org > > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails@lists.rubyonrails.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I''m not actually sure that it will - my understanding of the angle it is taking is a discussion of Ruby from the perspective of a Rails developer, since Rails has made popular a number of ruby ''tricks'', including: using :symbols instead of ''strings'' collecting method arguments => into, a => hash, without => {using => curly_braces} and so on. Ruby for people who came to Rails not knowing anything about Ruby. The Rails internals can be mystifying even for me, and I''ve been using Ruby since 2002 :) - james On 1/25/06, Joe Van Dyk <joevandyk@gmail.com> wrote:> On 1/25/06, James Adam <james.adam@gmail.com> wrote: > > Yes - d''oh! :) > > I hope David Black''s upcoming Rails book will illuminate this Rails > voodoo to me. I understand Ruby fairly well, but the Rails internals > are still magic. > > > On 1/25/06, Joe Van Dyk <joevandyk@gmail.com> wrote: > > > On 1/25/06, James Adam <james.adam@gmail.com> wrote: > > > > Constructor objects are actually created as part of the dispatcher > > > > process (dispatcher.rb, around line 38): > > > > > > Do you mean "Controller objects"? > > > > > > Joe > > > > > > > ActionController::Routing::Routes.recognize!(request).process(request, > > > > response).out(output) > > > > > > > > Basically, deep within the routing system the code generation > > > > performed by routing instantiates the relevant ApplicationController > > > > subclass (that call to recognize!() returns it, as I recall), and it > > > > needs to have control over which arguments are given. Joo don'' wanna > > > > mess wit dat. > > > > > > > > - james > > > > > > > > On 1/24/06, Tom Mornini <tmornini@infomania.com> wrote: > > > > > I''m not sure about controllers, but I found the hard way that Rails > > > > > disconnects model initialize methods for performance purposes... > > > > > > > > > > Perhaps the controllers are the same? > > > > > > > > > > -- > > > > > -- Tom Mornini > > > > > > > > > > > > > > > On Jan 24, 2006, at 10:32 AM, Joe Van Dyk wrote: > > > > > > > > > > > On 1/24/06, James Adam <james.adam@gmail.com> wrote: > > > > > >> You probably actually want to use a before_filter to perform some > > > > > >> initialization before performing an action, rather than use a > > > > > >> constructor at all... unless you have some very odd requirements. > > > > > > > > > > > > I don''t understand Rails internals at at all... so I''m curious. > > > > > > > > > > > > Why wouldn''t a constructor with a call to super work? > > > > > > > > > > > > Joe > > > > > > > > > > > >> On 1/24/06, Martijn van Leeuwen <ruby@martijnvanleeuwen.nl> wrote: > > > > > >>> Hi all, > > > > > >>> > > > > > >>> A little question. How can u use an constructor in controller? I > > > > > >>> would > > > > > >>> like to initialize some central stuff before i''m processing the > > > > > >>> controller. > > > > > >>> > > > > > >>> thanks in advance, > > > > > >>> > > > > > >>> Martijn > > > > > >>> > > > > > >>> _______________________________________________ > > > > > >>> Rails mailing list > > > > > >>> Rails@lists.rubyonrails.org > > > > > >>> http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > >>> > > > > > >> _______________________________________________ > > > > > >> Rails mailing list > > > > > >> Rails@lists.rubyonrails.org > > > > > >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > >> > > > > > > _______________________________________________ > > > > > > Rails mailing list > > > > > > Rails@lists.rubyonrails.org > > > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > _______________________________________________ > > > > > Rails mailing list > > > > > Rails@lists.rubyonrails.org > > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails@lists.rubyonrails.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >