Forum: Ruby on Rails Using Rails without a webpage

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.
Jan D. (Guest)
on 2006-03-10 16:10
(Received via mailing list)
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 ;) 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
Thibaut Barrère (Guest)
on 2006-03-10 16:49
(Received via mailing list)
Hi Jan

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

Thibaut
Jakob S. (Guest)
on 2006-03-11 12:48
(Received via mailing list)
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
Matt P. (Guest)
on 2006-03-11 23:39
(Received via mailing list)
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
This topic is locked and can not be replied to.