Where would this type of code go?

I’d like to create a command processor on the backend of a rails application and make it accessible in some way outside of the browser. So, for example, it might listen for connections on a particular port, or might watch a named pipe, or something else. This part is irrelevant.

The relevant part is that it needs access to models but needs to be outside of the standard Rails flow (i.e., http request to controller). So, the command processor might receive the command “start job 10”, and it should be able to update the database through the Rails app models, and possible also send results email through an ActionMailer. In other words, it would do everything your normal ActionController would do, without be started in response to an HTTP request.

Where is the proper place to put this within a rails application, and how would I make it capable of accessing my models?

Thanks guys.

Jake

try :

ruby script/console

but generally, ActiveRecord don't need be executed only via browser (that is via controller), so you could write a ruby-script using ActiveRecord (that is some of : Model<ActiveRecord)

Jake Cutter wrote:

what i do in this situation is create a rakefile under the lib/tasks folder. For example I have one called import.rake that imports some dummy data into the database. At the top of the file I have

ENV["RAILS_ENV"] = "development" require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")

and now my tasks can access all of the rails models. Then i define my import task and run it using rake import. However, as long as your ruby file has those two lines in it (the second one's path depending on the location of the file) then the ruby program can access all your models.

Jake Cutter wrote: