[Ruby] Where do you put Rails code that normally runs from a command line?

James Moore banshee at banshee.com
Tue May 23 10:30:53 PDT 2006


I've got some things for a Rails app that need to run from a command line.
Where do you normally put that code?  (Applying daily charges to customer
accounts, updating records that happen after scraping another side for
activity, and placing phone calls so far.)

Calling controller methods directly from runner doesn't work (and it's not
clear that it's the right place anyway):

[james at rubyvoice rv]$ ruby script/runner CustomerController.new.update
/usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/runner.rb:27:
/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependenc
ies.rb:123:in `const_missing': uninitialized constant ApplicationController
(NameError)
        from
/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependenc
ies.rb:131:in `const_missing'
...

Presumably getting this to work would be possible (I just haven't looked
into it much), since it's not much different than running a test from the
command line.

Right now I'm just putting the code into lib/ and calling them controllers,
but not having them inherit from ApplicationController.  This seems less
than elegant.  No problems getting it to work, just doesn't feel quite
right.

(Does this sort of thing belong here, or should I just go straight to the
Rails mailing list?  Are we trying to keep this to Seattle-specific
questions, basically?)

 - James



More information about the Ruby mailing list