I have a ruby class that will be used sometimes from within rails, and sometimes from without (not in the context of a running rails application). It will reference models within the rails app, and It may be run manually, or may be scheduled via Cron (though I may look at RailsCron as well). I''ve seen help on the Wiki for using models outside of Rails (like this article<http://wiki.rubyonrails.com/rails/pages/HowToUseActiveRecordOutsideRails>), but I''d rather not repeat my database configuration. Is there a better way to do this? -- Larry Wright http://www.approachingnormal.com http://www.welcometoparenthood.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060304/98453c32/attachment.html
Am Freitag, den 03.03.2006, 22:58 -0600 schrieb Larry Wright:> I have a ruby class that will be used sometimes from within rails, and > sometimes from without (not in the context of a running rails > application). It will reference models within the rails app, and It > may be run manually, or may be scheduled via Cron (though I may look > at RailsCron as well). I''ve seen help on the Wiki for using models > outside of Rails (like this article), but I''d rather not repeat my > database configuration. Is there a better way to do this?ENV[''RAILS_ENV''] = ARGV.first || ''development'' require File.dirname(__FILE__) + ''/../../config/boot'' require RAILS_ROOT + ''/config/environment'' I am using this few lines to load the Rails environment. After that code, you have a full functional rails environment. You can specify ''production'' or ''development'' mode as the first argument passed to the script. Don''t forget to adjust the relative path in line 2 to your needs. -- Norman Timmler http://blog.inlet-media.de
On 3/4/06, Norman Timmler <lists@inlet-media.de> wrote:> > Am Freitag, den 03.03.2006, 22:58 -0600 schrieb Larry Wright: > > I have a ruby class that will be used sometimes from within rails, and > > sometimes from without (not in the context of a running rails > > application). It will reference models within the rails app, and It > > may be run manually, or may be scheduled via Cron (though I may look > > at RailsCron as well). I''ve seen help on the Wiki for using models > > outside of Rails (like this article), but I''d rather not repeat my > > database configuration. Is there a better way to do this? > > ENV[''RAILS_ENV''] = ARGV.first || ''development'' > require File.dirname(__FILE__) + ''/../../config/boot'' > require RAILS_ROOT + ''/config/environment'' > > I am using this few lines to load the Rails environment. After that > code, you have a full functional rails environment. You can specify > ''production'' or ''development'' mode as the first argument passed to the > script. Don''t forget to adjust the relative path in line 2 to your > needs. > -- > Norman Timmler > > http://blog.inlet-media.de > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >That worked perfectly. Thanks. -- Larry Wright http://www.approachingnormal.com http://www.welcometoparenthood.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060305/0e83ffd0/attachment-0001.html