Rails application to run commands on remote machine
===

I have a Ruby on Rails 3 application, that I would like to control a remote machine via SSH access.

Basically I would like the Rails application to be able to edit files, copy them, move directories, etc. on a remote machine via SSH.

I have already created Capistrano tasks for the functions I would like to execute, but I would like to know:

1. What is the best practice of running remote shell code from Rails
2. How can I invoke Capistrano tasks from a Rails application (which would basically achieve 1)

Thanks!