Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commandline statement inside rails controller

How to execute rails commandline statement inside our rails controller

eg: I need to execute this statement

$rails new test -d postgresql

from my rails controller

def index

/Code to execute the command line statement/

end

Hope am clear..

like image 322
Yothesh Avatar asked Aug 14 '12 08:08

Yothesh


3 Answers

If you want to run shell commands inside controller just use "system"

Eg:

system "rails new test -d postgresql"

or else

exec "rails new test -d postgresql"
like image 85
pdpMathi Avatar answered Nov 05 '22 09:11

pdpMathi


Use backticks to shell out, like this:
`rails new test -d postgresql`

It might be smarter to use a job queue for this.

like image 34
Nils Landt Avatar answered Nov 05 '22 09:11

Nils Landt


To run command line statements inside controller, we can use system command

system "cd {path_to_folder}; rails new test -d postgresql"
like image 3
PradeepKumar Avatar answered Nov 05 '22 10:11

PradeepKumar