Execute Scripts from a Controller

Is there an easy way to runs things like script/generate and
db:migrate from within a controller?

Jorg L. wrote:

Is there an easy way to runs things like script/generate and
db:migrate from within a controller?

no not that I now of…
but why would you like to that ?

for example if you set up you application for production you only have
to call rake db:migrate one time.
(if you have set up your migrations as it should be of course :stuck_out_tongue: )
I have never come across a problem that would need to run a shell
command.

Jorg L. wrote:

Is there an easy way to runs things like script/generate and
db:migrate from within a controller?

This will work (at least on Rails 1.2.3):
if ENV[“OS”] == “Windows_NT”
rake.bat db:migrate
else
rake db:migrate
end

Norm wrote:

Jorg L. wrote:

Is there an easy way to runs things like script/generate and
db:migrate from within a controller?

This will work (at least on Rails 1.2.3):
if ENV[“OS”] == “Windows_NT”
rake.bat db:migrate
else
rake db:migrate
end

O sorry I didn’t now that would work…
one question though… why would you want to run db:migrate in a rails
app ?

jeljer te Wies wrote:

`rake.bat db:migrate`

else
rake db:migrate
end

O sorry I didn’t now that would work…
one question though… why would you want to run db:migrate in a rails
app ?
In my case I do it to automatically update my database when the app is
run. This is for an app that is a little different from the
conventional Rails app. The app is run on the local network and may be
installed and maintained by minimally knowledgeable persons. It is
easier to do the migration automatically than to explain how and why and
when to run it. I have it set up to get the current version and only
run the migration if it is needed.

I doubt it would be the best way. But if users want to create whole
new objects running the script/generate scaffold would instantly
generate the CRUD views. But I’m thinking of doing this a bit
differently now.

Maybe the people define the elements and that definition gets stored
while the data is serialized.

On Aug 26, 12:25 pm, jeljer te Wies [email protected]

This concept won’t work too well in a production environment…

On Tue, Aug 26, 2008 at 1:13 PM, Jorg L. [email protected]
wrote:

wrote:

I have never come across a problem that would need to run a shell
command.


Posted viahttp://www.ruby-forum.com/.


Robby R.
Chief Evangelist, Partner

PLANET ARGON, LLC
design // development // hosting

http://www.robbyonrails.com/
aim: planetargon

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4068 [fax]

There doesn’t seem to be a well-working concept for dynamic resource
generation and storage as far as I can tell. It may be best to let
people define the new forms and use them but then make them permanent
for future use once per day. That way users get to be happy that they
can create and use somehting instantly, plus the schema can then be
updated normally once per unit time.

Or is there an elegant solution for dynamically building objects?

Use the “spawn” plugin and move the execution to a background
process. You can use Ruby’s “system” command from the Kernel or the
Shell::CommandProcessor

http://www.ruby-doc.org/core/

Worth a peek