I have controller that processes data in one table and puts results in another. Now that its'' working, I would like to be able to run it from the command line ( read: windows batch file). How can this be done? It will be installed on a Windows box with InstantRails1.0, (if that matters). I will be doing more processes like this, so this is a good opportunity to get it right. -- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060203/ca917e81/attachment.html
I think you can do that with the "runner" script that rails creates for you in the script directory of your project. It uses the environment created by rails, so you can say something like "ruby script\runner MyClass.do_something("myarg")". This wiki page mentions it at the bottom... there are probably others: http://wiki.rubyonrails.com/rails/pages/Environments#script b Larry Kelly wrote:> I have controller that processes data in one table and puts results in > another. Now that its'' working, I would like to be able to run it from > the command line ( read: windows batch file). How can this be done? > > It will be installed on a Windows box with InstantRails1.0, (if that > matters). > > I will be doing more processes like this, so this is a good opportunity > to get it right. > > -- > Best Regards, > -Larry > "Work, work, work...there is no satisfactory alternative." > --- E.Taft Benson > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Larry, like Ben says you can use "$RAILS_ROOT/script/runner" to invoke ruby code from the command line, which will run in a full Rails environment. I would additionally suggest that you factor your code out of the controller. Controllers are fairly specific to their role in a web framework. They expect to be run in the context of a request that arrived via the web. So depending on what exactly your code does, I would put it in a model or a lib file. Then you can call that code from your controller, and via script/runner. cheers Gerret On 2/3/06, Ben Munat <bent@munat.com> wrote:> I think you can do that with the "runner" script that rails creates for you in the script directory of your project. It > uses the environment created by rails, so you can say something like "ruby script\runner MyClass.do_something("myarg")". > > This wiki page mentions it at the bottom... there are probably others: > > http://wiki.rubyonrails.com/rails/pages/Environments#script > > b > > Larry Kelly wrote: > > I have controller that processes data in one table and puts results in > > another. Now that its'' working, I would like to be able to run it from > > the command line ( read: windows batch file). How can this be done? > > > > It will be installed on a Windows box with InstantRails1.0, (if that > > matters). > > > > I will be doing more processes like this, so this is a good opportunity > > to get it right. > > > > -- > > Best Regards, > > -Larry > > "Work, work, work...there is no satisfactory alternative." > > --- E.Taft Benson > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > 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 >
Thanks, Ben and Gerret! I was thinking that the controller was probably not the best place for code that doesn''t need to call a web page. Just wasn''t sure was is should go. Thanks for that tip, as well. Why would I choose a lib location over a model? -Larry On 2/4/06, Gerret Apelt <gerret.apelt@gmail.com> wrote:> > Larry, > > like Ben says you can use "$RAILS_ROOT/script/runner" to invoke ruby > code from the command line, which will run in a full Rails > environment. > > I would additionally suggest that you factor your code out of the > controller. Controllers are fairly specific to their role in a web > framework. They expect to be run in the context of a request that > arrived via the web. > > So depending on what exactly your code does, I would put it in a model > or a lib file. Then you can call that code from your controller, and > via script/runner. > > cheers > Gerret > > On 2/3/06, Ben Munat <bent@munat.com> wrote: > > I think you can do that with the "runner" script that rails creates for > you in the script directory of your project. It > > uses the environment created by rails, so you can say something like > "ruby script\runner MyClass.do_something("myarg")". > > > > This wiki page mentions it at the bottom... there are probably others: > > > > http://wiki.rubyonrails.com/rails/pages/Environments#script > > > > b > > > > Larry Kelly wrote: > > > I have controller that processes data in one table and puts results > in > > > another. Now that its'' working, I would like to be able to run it from > > > the command line ( read: windows batch file). How can this be done? > > > > > > It will be installed on a Windows box with InstantRails1.0, (if that > > > matters). > > > > > > I will be doing more processes like this, so this is a good > opportunity > > > to get it right. > > > > > > -- > > > Best Regards, > > > -Larry > > > "Work, work, work...there is no satisfactory alternative." > > > --- E.Taft Benson > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > 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 >-- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060204/80ff6564/attachment.html
Hi Larry -- the model files should contain, well, model-specific code, while the ''/lib'' location holds libraries specific to your application that are not related to a particular model. You write that your code takes "data in one table and puts results in another", so without knowing the details, I would guess you write some sort of "export" or "convert" function in your source model class. cheers Gerret On 2/4/06, Larry Kelly <larry@tellinkltd.com> wrote:> Thanks, Ben and Gerret! > > I was thinking that the controller was probably not the best place for code > that doesn''t need to call a web page. Just wasn''t sure was is should go. > Thanks for that tip, as well. Why would I choose a lib location over a > model? > -Larry > > > On 2/4/06, Gerret Apelt <gerret.apelt@gmail.com> wrote: > > Larry, > > > > like Ben says you can use "$RAILS_ROOT/script/runner" to invoke ruby > > code from the command line, which will run in a full Rails > > environment. > > > > I would additionally suggest that you factor your code out of the > > controller. Controllers are fairly specific to their role in a web > > framework. They expect to be run in the context of a request that > > arrived via the web. > > > > So depending on what exactly your code does, I would put it in a model > > or a lib file. Then you can call that code from your controller, and > > via script/runner. > > > > cheers > > Gerret > > > > On 2/3/06, Ben Munat <bent@munat.com> wrote: > > > I think you can do that with the "runner" script that rails creates for > you in the script directory of your project. It > > > uses the environment created by rails, so you can say something like > "ruby script\runner MyClass.do_something("myarg")". > > > > > > This wiki page mentions it at the bottom... there are probably others: > > > > > > > http://wiki.rubyonrails.com/rails/pages/Environments#script > > > > > > b > > > > > > Larry Kelly wrote: > > > > I have controller that processes data in one table and puts results > in > > > > another. Now that its'' working, I would like to be able to run it from > > > > the command line ( read: windows batch file). How can this be done? > > > > > > > > It will be installed on a Windows box with InstantRails1.0, (if that > > > > matters). > > > > > > > > I will be doing more processes like this, so this is a good > opportunity > > > > to get it right. > > > > > > > > -- > > > > Best Regards, > > > > -Larry > > > > "Work, work, work...there is no satisfactory alternative." > > > > --- E.Taft Benson > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > _______________________________________________ > > > > 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 > > > > > > -- > > Best Regards, > -Larry > "Work, work, work...there is no satisfactory alternative." > --- E.Taft Benson > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
This seems a little weird to me... shouldn''t /lib contain stuff that''s not application-dependent? If so, code that knows how to move stuff around in the current application would be application dependent. Seems like rails needs an "/etc" or "/util" directory under "/app". Or maybe db manipulation stuff could be considered not part of the app... but tied to the app... Hmm, or maybe I''m over-thinking this... :-) b Gerret Apelt wrote:> Hi Larry -- the model files should contain, well, model-specific code, > while the ''/lib'' location holds libraries specific to your application > that are not related to a particular model. You write that your code > takes "data in one table and puts results in another", so without > knowing the details, I would guess you write some sort of "export" or > "convert" function in your source model class. > > cheers > Gerret > > On 2/4/06, Larry Kelly <larry@tellinkltd.com> wrote: > >>Thanks, Ben and Gerret! >> >>I was thinking that the controller was probably not the best place for code >>that doesn''t need to call a web page. Just wasn''t sure was is should go. >>Thanks for that tip, as well. Why would I choose a lib location over a >>model? >>-Larry >> >> >>On 2/4/06, Gerret Apelt <gerret.apelt@gmail.com> wrote: >> >>>Larry, >>> >>>like Ben says you can use "$RAILS_ROOT/script/runner" to invoke ruby >>>code from the command line, which will run in a full Rails >>>environment. >>> >>>I would additionally suggest that you factor your code out of the >>>controller. Controllers are fairly specific to their role in a web >>>framework. They expect to be run in the context of a request that >>>arrived via the web. >>> >>>So depending on what exactly your code does, I would put it in a model >>>or a lib file. Then you can call that code from your controller, and >>>via script/runner. >>> >>>cheers >>>Gerret >>> >>>On 2/3/06, Ben Munat <bent@munat.com> wrote: >>> >>>>I think you can do that with the "runner" script that rails creates for >> >>you in the script directory of your project. It >> >>>>uses the environment created by rails, so you can say something like >> >>"ruby script\runner MyClass.do_something("myarg")". >> >>>>This wiki page mentions it at the bottom... there are probably others: >>>> >>>> >> >>http://wiki.rubyonrails.com/rails/pages/Environments#script >> >>>>b >>>> >>>>Larry Kelly wrote: >>>> >>>>>I have controller that processes data in one table and puts results >> >>in >> >>>>>another. Now that its'' working, I would like to be able to run it from >>>>>the command line ( read: windows batch file). How can this be done? >>>>> >>>>>It will be installed on a Windows box with InstantRails1.0, (if that >>>>>matters). >>>>> >>>>>I will be doing more processes like this, so this is a good >> >>opportunity >> >>>>>to get it right. >>>>> >>>>>-- >>>>>Best Regards, >>>>>-Larry >>>>>"Work, work, work...there is no satisfactory alternative." >>>>> --- E.Taft Benson >>>>> >>>>> >>>>> >> >>------------------------------------------------------------------------ >> >>>>>_______________________________________________ >>>>>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 >>> >> >> >> >>-- >> >>Best Regards, >> -Larry >>"Work, work, work...there is no satisfactory alternative." >> --- E.Taft Benson >>_______________________________________________ >>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
Actually, the completed app will read data from DB2 and MySQL databases and store them in a local MySQL database after processing. On 2/4/06, Gerret Apelt <gerret.apelt@gmail.com> wrote: Hi Larry -- the model files should contain, well, model-specific code,> while the ''/lib'' location holds libraries specific to your application > that are not related to a particular model. You write that your code > takes "data in one table and puts results in another", so without > knowing the details, I would guess you write some sort of "export" or > "convert" function in your source model class. > > cheers > Gerret > > On 2/4/06, Larry Kelly < larry@tellinkltd.com> wrote: > > Thanks, Ben and Gerret! > > > > I was thinking that the controller was probably not the best place for > code > > that doesn''t need to call a web page. Just wasn''t sure was is should > go. > > Thanks for that tip, as well. Why would I choose a lib location over a > > model? > > -Larry > > > > > > On 2/4/06, Gerret Apelt <gerret.apelt@gmail.com > wrote: > > > Larry, > > > > > > like Ben says you can use "$RAILS_ROOT/script/runner" to invoke ruby > > > code from the command line, which will run in a full Rails > > > environment. > > > > > > I would additionally suggest that you factor your code out of the > > > controller. Controllers are fairly specific to their role in a web > > > framework. They expect to be run in the context of a request that > > > arrived via the web. > > > > > > So depending on what exactly your code does, I would put it in a model > > > or a lib file. Then you can call that code from your controller, and > > > via script/runner. > > > > > > cheers > > > Gerret > > > > > > On 2/3/06, Ben Munat <bent@munat.com> wrote: > > > > I think you can do that with the "runner" script that rails creates > for > > you in the script directory of your project. It > > > > uses the environment created by rails, so you can say something like > > "ruby script\runner MyClass.do_something("myarg")". > > > > > > > > This wiki page mentions it at the bottom... there are probably > others: > > > > > > > > > > http://wiki.rubyonrails.com/rails/pages/Environments#script > > > > > > > > b > > > > > > > > Larry Kelly wrote: > > > > > I have controller that processes data in one table and puts > results > > in > > > > > another. Now that its'' working, I would like to be able to run it > from > > > > > the command line ( read: windows batch file). How can this be > done? > > > > > > > > > > It will be installed on a Windows box with InstantRails1.0, (if > that > > > > > matters). > > > > > > > > > > I will be doing more processes like this, so this is a good > > opportunity > > > > > to get it right. > > > > > > > > > > -- > > > > > Best Regards, > > > > > -Larry > > > > > "Work, work, work...there is no satisfactory alternative." > > > > > --- E.Taft Benson > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > > > _______________________________________________ > > > > > 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 > > > > > > > > > > > -- > > > > Best Regards, > > -Larry > > "Work, work, work...there is no satisfactory alternative." > > --- E.Taft Benson > > _______________________________________________ > > 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 >-- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060205/50d654ee/attachment-0001.html