Hi, Sorry for a very basic question, but... Where should I put objects and libraries I develop and share among the controllers? I tried to put them in the lib directory, but then I need to restart the server each time I make a change to the object because of caching. So, is there a better place to put them? Thanks! -- Posted via http://www.ruby-forum.com/.
On Tue, 2005-12-06 at 19:59 +0100, Kåre wrote:> Hi, > > Sorry for a very basic question, but... > > Where should I put objects and libraries I develop and share among the > controllers? I tried to put them in the lib directory, but then I need > to restart the server each time I make a change to the object because of > caching. > > So, is there a better place to put them? > > Thanks! >I believe if you manually require it as a dependency, it will reload it when the file changes. I think the right spot for this require is in environment.rb? require_dependency ''foo'' Either that, or figure out what structure you need to make a plugin out of it and stick it in vendor. I think the purpose for /lib is any 3rd party ruby modules that are unlikely to change (3rd party rails modules being either plugins or engines, going in /vendor). - Jamie
On Dec 6, 2005, at 11:30 AM, Jamie Macey wrote:> On Tue, 2005-12-06 at 19:59 +0100, Kåre wrote: >> Hi, >> >> Sorry for a very basic question, but... >> >> Where should I put objects and libraries I develop and share among >> the >> controllers? I tried to put them in the lib directory, but then I >> need >> to restart the server each time I make a change to the object >> because of >> caching. >> >> So, is there a better place to put them? >> >> Thanks! >> > > I believe if you manually require it as a dependency, it will > reload it > when the file changes. I think the right spot for this require is in > environment.rb? > > require_dependency ''foo'' > > Either that, or figure out what structure you need to make a plugin > out > of it and stick it in vendor. I think the purpose for /lib is any 3rd > party ruby modules that are unlikely to change (3rd party rails > modules > being either plugins or engines, going in /vendor). > > - Jamierequire_dependency is the right way to go but it unfortunately wont work in the environment.rb since that file is only loaded once on startup. So you might want to put the require_dependency in your application.rb for development mode so that it reloads on each request. then once its tested and ready for the world you can require it in environment.rb for production. Cheers- -Ezra Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org
If the files in lib are to be used by your controllers then you put the require_dependency call in your controllers/application.rb file (or whatever controller is using the lib). I''m fairly certain that if you put the require_dependency in your environment.rb file it will only be evaluated once (at boot time). Sticking it in your controllers/application.rb file will ensure it''s evaluated for each request (in development mode) so it will pick up your changes. Regards, Trevor On 6-Dec-05, at 11:30 AM, Jamie Macey wrote:> On Tue, 2005-12-06 at 19:59 +0100, Kåre wrote: >> Hi, >> >> Sorry for a very basic question, but... >> >> Where should I put objects and libraries I develop and share among >> the >> controllers? I tried to put them in the lib directory, but then I >> need >> to restart the server each time I make a change to the object >> because of >> caching. >> >> So, is there a better place to put them? >> >> Thanks! >> > > I believe if you manually require it as a dependency, it will > reload it > when the file changes. I think the right spot for this require is in > environment.rb? > > require_dependency ''foo'' > > Either that, or figure out what structure you need to make a plugin > out > of it and stick it in vendor. I think the purpose for /lib is any 3rd > party ruby modules that are unlikely to change (3rd party rails > modules > being either plugins or engines, going in /vendor). > > - Jamie > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/railsTrevor Squires http://somethinglearned.com