Using Rails without a webpage

Hi,

I’m thinking of how it may be possible to execute Rails code without
having to load a webpage which invokes the controller/actions.
Background is: I have a public-website which reads from a DB, nothing
special yet :wink: Due to internal processes in the company we thought of
instead having an admintool to fill the DB we maybe could use a script
or something which fills the DB. And to have all the nice Rails-features
in a “script” (batchfile or whatever) which receives the needed
parameters and gets executed manually - instead of having to click in a
scaffold-like web-interface. I know I can execute Ruby code on the
console, but then I don’t have the Rails features like ORM-mapping etc.

Any hints or pointers to some documentation on this issue are welcome!

bye
Jan

Hi Jan

you can just write a ruby application which would rely on activerecord
(without the whole rails package)

Thibaut

On Mar 10, 2006, at 14:46, Jan D. wrote:

I’m thinking of how it may be possible to execute Rails code without
having to load a webpage which invokes the controller/actions.

Any hints or pointers to some documentation on this issue are welcome!

You can execute code from script in the Rails environment by using
script/runner. ie script/runner 'Model.method(“foo”); will execute
method on Model with “foo” as parameter.


Jakob S. - http://mentalized.net

On Fri, Mar 10, 2006 at 02:46:49PM +0100, Jan D. wrote:

I’m thinking of how it may be possible to execute Rails code without
having to load a webpage which invokes the controller/actions.

Yes. You can write a method (typically a controller action) which does
what
you need it to do, and then invoke that method via script/runner.
Alternately, if you only need a certain subset of Rails’ features, such
as
ActiveRecord, you can write a standalone Ruby script that performs the
necessary actions after “require ‘active_record’”. Thirdly, you can use
a
mangled version of script/runner to actually provide a real “command
line”
invoker – I’ve got one that runs a method on a particular controller
which
matches the command name that the script was invoked as, and then
symlink
all of my command names to that script. With a standard signature for
all
of those methods, you’ve got a simple and powerful way to do command
line
programs in Rails.

I’ve used all of these methods to great effect in my projects. Which
one is
most appropriate for you depends entirely on what you need to do.

  • Matt