
Our Web hosting service includes full support for Ruby scripts. We also have Ruby on Rails preinstalled.
Our servers currently use Ruby 1.8.2 (with Debian security patches) and Rails 1.2.6, although you can choose your own Rails version. Note that the system-wide Rails version can change without notice, so be sure to read the section below about choosing a Rails version to make sure your Rails app doesn't "bind" itself to a version that might not exist in the future.
On this page:
There's nothing particularly special about using Ruby on our servers; if you download a script from elsewhere, it should work. Here are some tips:
Make sure that the first line of your script points to the correct location of Ruby on our servers. You can use either of these paths:
#!/usr/bin/ruby #!/usr/bin/ruby1.8
Use your FTP program to upload the script file in text mode (sometimes called "ASCII mode"), not "binary" mode. Although text mode is the default for most FTP programs, your Ruby script may not work if it's accidentally uploaded using binary mode, so it's wise to check.
When you upload the script, place it in a directory (folder) named cgi-bin using your FTP program. You will need to create this directory the first time you upload a script.
(Advanced users can make other directories run scripts like the "cgi-bin" directory; see our "Making Additional Directories Executable" page for more information.)
Set the file permissions to make your script "executable" after uploading (you'll sometimes see this process referred to as making the script permissions "mode 0755" or "mode 0700").
Your FTP program documentation should explain how to create directories, transfer a file in ASCII mode, and change the permissions of a file you've uploaded.
You can use our Script Checker to verify that the script was uploaded properly. The page also gives you a quick way to make the file executable if you prefer to do that on the Web, rather than using your FTP program.
Once your Ruby script is installed, you'll access it as:
http://www.example.com/cgi-bin/script.rb
... where "script.rb" is the actual name of your Ruby script.
Ruby on Rails is a powerful Web development environment that is quickly becoming popular. Most Rails applications should work by following the installation instructions that come with them.
One of the reasons for the popularity of Rails is that it allows you to easily create your own applications. While we unfortunately can't offer support for programming questions, the information below demonstrates how advanced users could create a new Rails application.
Make a telnet or SSH connection, then change to the html directory:
cd html
Rails can automatically create a new application for you. We'll call this one railstest. Just type:
rails railstest
This creates a directory named railstest to contain the application. Change into that directory:
cd railstest
At this point, you should be able to go to a URL like http://www.example.com/railstest/public/ in a Web browser and see a working default Rails application. (Enter your domain name in the box at the top of this page to see the exact URL.)
To make your Rails application do something other than the default, create a new controller class. We'll call it "test". Type:
script/generate controller test
Among other things, this creates a new file at app/controllers/test_controller.rb.
Edit the controller file using your favorite text editor, such as nano:
nano app/controllers/test_controller.rb
The file initially contains no special code — it looks like this:
class TestController < ApplicationController end
You can add a few lines of code so it looks like this:
class TestController < ApplicationController
def hello
render :text => "Hello World!"
end
end
After saving that file, you should be able to view a URL like http://www.example.com/railstest/public/test/hello in a Web browser. (Enter your domain name in the box at the top of this page to see the exact URL.)
With the information above, advanced users should be able to make sense of the ONLamp Rails tutorial, which has a lot more details about Rails. If you have questions about Rails, Google's Ruby on Rails group is a great place to start.
If you create your own new Rails application as described above, the app will "bind" itself to the current installed version of Ruby Gems using RAILS_GEM_VERSION in config/environment.rb. This is not what you want to happen on a server where you don't control the Rails installation: in particular, it means your application won't work when Rails is upgraded and the old version removed from the server (we keep old versions around as long as possible, but they will eventually need to be removed — we probably won't have Rails 1.0 still installed on all our servers five years from now).
Instead, you'll want to either "comment out" the RAILS_GEM_VERSION line in the config/environment.rb file (which will make your application always use the latest version of Rails available on the server: this is good for security, but can cause compatibility problems) or freeze the version of Rails used by your application (which gives you much more control over what's happening: you can use any version of Rails you wish).
We do upgrade Rails on a regular basis, so if you're concerned about compatibility, you'll probably want to choose your own version by freezing Rails. Doing so makes sure you aren't affected when we upgrade Rails on our servers (but means you'll need to keep track of when new versions of Rails are available so you can upgrade your application).
If you've tried the above example, or you've installed a Rails application, you may notice that Rails is quite slow by default. To speed up Rails applications, we support FastCGI (and we use mod_fcgid as the Rails documentation recommends).
To enable FastCGI for Rails, edit the .htaccess file in the public directory of your Rails application. Replace this line:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
With this:
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
(In other words, change ".cgi" to ".fcgi", just as the comments in the file suggest.) Your Rails application should now run much more quickly when it's reloaded.