Forum: Ruby on Rails Rails from the command line

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Larry K. (Guest)
on 2006-02-03 22:49
(Received via mailing list)
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
Ben M. (Guest)
on 2006-02-03 22:59
(Received via mailing list)
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
Gerret A. (Guest)
on 2006-02-04 14:43
(Received via mailing list)
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
Larry K. (Guest)
on 2006-02-04 15:05
(Received via mailing list)
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 A. <removed_email_address@domain.invalid> wrote:
> arrived via the web.
> you in the script directory of your project. It
> > > I have controller that processes  data in one table and puts results
> > >
> > > _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>



--
Best Regards,
-Larry
"Work, work, work...there is no satisfactory alternative."
            --- E.Taft Benson
Gerret A. (Guest)
on 2006-02-04 15:41
(Received via mailing list)
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
Ben M. (Guest)
on 2006-02-04 22:52
(Received via mailing list)
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
Larry K. (Guest)
on 2006-02-05 03:15
(Received via mailing list)
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 A. <removed_email_address@domain.invalid> wrote:

Hi Larry -- the model files should contain, well, model-specific code,
> > Thanks, Ben and Gerret!
> > On 2/4/06, Gerret A. <removed_email_address@domain.invalid > wrote:
> > >
> > you in the script directory of your project. It
> > > >
> that
> > > > >             --- E.Taft Benson
> > > > _______________________________________________
> >
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
> >
> >
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>



--
Best Regards,
-Larry
"Work, work, work...there is no satisfactory alternative."
            --- E.Taft Benson
This topic is locked and can not be replied to.