Peter Piper
2006-Feb-17 11:09 UTC
[Rails] How to get RAILS_ROOT when writing a ruby utility in /lib
Hi, Im writing a small ruby utility which at the moment is in /lib of my rails app. However I don''t get access to var''s like RAILS_ROOT, do I need to add an include to get this (and possibily other) rails functionality? Is /lib the right place for this kind of app, its a single ruby class which I call from the command line. Would a rake file be better for this kind of thing? Can rake''s run ruby code,, im guessing yes? Many thanks, K. -- Posted via http://www.ruby-forum.com/.
Chris Hall
2006-Feb-17 12:32 UTC
[Rails] How to get RAILS_ROOT when writing a ruby utility in /lib
i put my utility scripts in the script directory. for me, a utility script is something that i need to run at the command line or in cron (ex: clearing out old session files) put this at the top of your script: # load application environment require File.dirname(__FILE__) + ''/../config/environment'' this will give you access to the RAILS_ROOT constant. you also might be interested in script/runner Chris On 2/17/06, Peter Piper <peter@nospam.com> wrote:> > Hi, Im writing a small ruby utility which at the moment is in /lib of my > rails app. However I don''t get access to var''s like RAILS_ROOT, do I > need to add an include to get this (and possibily other) rails > functionality? > > Is /lib the right place for this kind of app, its a single ruby class > which I call from the command line. Would a rake file be better for this > kind of thing? Can rake''s run ruby code,, im guessing yes? > > Many thanks, K. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060217/55e32d32/attachment.html
Kris Leech
2006-Feb-17 14:18 UTC
[Rails] Re: How to get RAILS_ROOT when writing a ruby utility in /li
Many thanks Chris! Chris Hall wrote:> i put my utility scripts in the script directory. for me, a utility > script > is something that i need to run at the command line or in cron (ex: > clearing > out old session files) > > put this at the top of your script: > > # load application environment > require File.dirname(__FILE__) + ''/../config/environment'' > > this will give you access to the RAILS_ROOT constant. > > > you also might be interested in script/runner > > Chris-- Posted via http://www.ruby-forum.com/.
Joe
2006-Feb-17 20:36 UTC
[Rails] Re: How to get RAILS_ROOT when writing a ruby utility in /li
Chris Hall wrote:> > put this at the top of your script: > > # load application environment > require File.dirname(__FILE__) + ''/../config/environment'' > > this will give you access to the RAILS_ROOT constant. > > > you also might be interested in script/runnerUsing script/runner still doesn''t give access to RAILS_ROOT and other config stuff (I kinda think it should), so the require is still required. Joe -- Posted via http://www.ruby-forum.com/.