Hello all, just started tinkering with Rails after reading all the hype about it. I''m a raw novice with Ruby and (obviously) Rails, but have extensive experience with serverside Java (J2EE stack, Tapestry, etc). Rails looks cool, though embedding Ruby code in HTML reminds me unpleasantly of JSP + Struts and I''m deeply suspicious of all the behind-the-scenes magic going on in Rails. But I''ll bury my misgivings and give this thing a whirl :). Anyway, a question: with Java servlets (and servlet-based frameworks) I''m used to being able to initialize some "expensive" stuff at app startup as singletons and then store them away (servlet context, JNDI, whatever) for later use by the app request-handling code. Now, this is obviously impossible with straight cgi-script style Rails with separate script invocations per request, but can I do something like this with Webrick, mod_ruby etc? As a concrete example, I''d like to initialize a Copland registry as a singleton when a Rails app starts up, and then use that in the Rails code to fetch my own code modules when I need them. Can I do this, and if yes what''s the appropriate place in Rails to plug in the initialization code? All help appreciated. //Petri
Petri Wessman wrote:> As a concrete example, I''d like to initialize a Copland registry as a > singleton when a Rails app starts up, and then use that in the Rails code to > fetch my own code modules when I need them. Can I do this, and if yes what''s > the appropriate place in Rails to plug in the initialization code?config/environment.rb is run when a new app instance is started. Set up your registry in config/registry.rb and add require ''config/registry'' to the end of config/environment.rb Have you seen Needle? It''s Copland''s successor. Best, jeremy
On Wednesday 30 March 2005 20:36, Jeremy Kemper wrote:> Petri Wessman wrote: > > As a concrete example, I''d like to initialize a Copland registry as a > > singleton when a Rails app starts up, and then use that in the Rails code > > to fetch my own code modules when I need them. Can I do this, and if yes > > what''s the appropriate place in Rails to plug in the initialization code? > > config/environment.rb is run when a new app instance is started. > > Set up your registry in config/registry.rb and add > require ''config/registry'' > to the end of config/environment.rbOk, thanks, that sounds pretty nice and elegant. I had already figured out that environment.rb is probably the right place, but it''s nice to have that confirmed :).> Have you seen Needle? It''s Copland''s successor. > Best, > jeremyHeard of it but haven''t taken a look until a few minutes ago, I hadn''t realized that it''s Copland''s successor, I had thought it ws "just" another IoC container. But thanks, if it''s the one getting active development then it''s obviously the way to go. I like HiveMind on the Java side, and googling originally turned Copland up first. IoC is one of those things that you don''t want to give up once you get used to it, it''s a damn good way of compartmentaizing and building modular code (IMHO, of course). Ok, off to tinker some more... ;) //Petri