Yes, you can run Ruby on Windows and eRuby on Windows IIS web servers. Ruby has many features to process text files and to do system management tasks as languages like Perl or Python do. Ruby is simple, straight-forward, extensible, and cross-platform portable language that has a syntax that is easy to understand. One of the strengths of Ruby is that it strives to be powerful but not complicated. Ruby has advantage over other OOP languages in that it can be used to code procedurally. Now you can use Ruby on your Windows IIS web server by setting up eRuby to process *.rhtml pages.
eRuby is an extension to Ruby that allows you to use the power of Ruby and embed its code into HTML files. The way eRuby does this is by inversing the HTML code into print statements before sending the code on to be interpreted. Code in the HTML file is translated into a mix of single and multi-line commands. This is all sent to the Ruby CGI interpreter for processing. eRuby is an easy way of using, learning and getting the power of Ruby on to a website. With eRuby deployment is a easy as uploading your files to your web server. This is to say deploying an application or webpage is no harder in eRuby than it's counterparts like PHP or ASP. I honestly believe that if Ruby popularity is going to increase that eRuby will be the reason. Unlike Rails eRuby has a very shallow learning curve and does not require a lot of effort by web hosting companies to set up.
In this tutorial I am going to assume a few things that require that you be familiar with the technology used. This tutorial is not intended to be a lesson on the Ruby language but on how to get started by setting up both a working development and production environment. Once you get your set up going you can go on to other articles covering how to do some useful applications in Ruby.
Is you are running a server edition of Windows then you may already have IIS installed and ready to go. If you are running Windows 2000 Pro or Windows XP you may have to go to one of the many tutorials on how to get IIS up and running on a Windows workstation. I am not going to give a tutorial on this and assume that if you want to use Ruby on IIS it is because you already have IIS on your PC. Here I using Windows 2000 server which is IIS5. If you are using Windows XP or Windows 2003 then IIS6 will be your web server. There should not be any differences with the exception that IIS6 needs a security setting to allow eruby.exe to work.
This is a single file that will install ruby on to your Windows computer. The only thing you have to do is click once or twice and wait. It contains the Ruby language itself, dozens of popular extensions and packages, a syntax-highlighting editor and execution environment, and a Windows help file that contains the full text of the book, Programming Ruby: The Pragmatic Programmer's Guide. Click on the executable and follow the instructions. Ruby is also set into the your Windows path so that you can run it from any directory.
To interpret HTML pages that have Ruby code embedded in them you need a windows binary of the eRuby interpreter. You can either compile this binary yourself using minGW or you can use the pre-compiled file dowloadable from one of the minGW mirrors. Once you have downloaded the binary add the eruby.exe to the bin directory where you installed Ruby.
This tutorial is not geared towards the raw beginner so I will go straight to the instruction set for configuring the IIS web server. If you have never done this before then you may want to read up on it and train a bit before going further.
1. Go to Start->settings->controlpanel then click on the Administrative tools->Internet Information Services icons to open the administration window right click on the default web site or the website that will run Ruby and eRuby and click on "properties" to bring up the properties box. Go to the "home directory" tab and click on "configuration" then "add" what you get should look like the image below. Browse to your eruby.exe and then fill in the file type as ".rhtml". Save and restart the server if necessary.

2. Save this in c:/inetpub/www (or whereever you have your root directory set) as eruby_test.rhtml, run it.
<html>
<head>
<title>Welcome to eruby Test</title>
</head>
<body>
<h2>eRuby test</h2>
<pre>
<%
3.times {
puts "Hello World"
}
%>
</pre>
</body>
</html>
To gain access to the CGI executable on a shared web host you should use .htaccess. It is a simple thing and it allows you to control where eRuby can be used on the directory system.
DirectoryIndex index.rhtml index.html index.htm AddHandler rubypage .rhtml Action rubypage /eruby.cgi
If your web host has eruby installed and you have access to ssh then you will only have to copy eruby from the server to your accounts root folder. When you copy the files from the folder it will auto-matically be renamed eruby.cgi
$ cp local/bin/eruby public_html/cgi-bin/eruby
You can also compile your own eRuby and install it if your web host allows this on their servers. In most cases copying the web hosts file is best because you know that it is working and safe. But you may be in a situation where the web host has not installed eRuby but has nothing against you doing it yourself.
$ cd ~ $ wget http://www.modruby.net/archive/eruby-1.0.5.tar.gz $ tar zxvf eruby-1.0.5.tar.gz $ cd eruby-1.0.5 $ ./configure.rb --prefix=$HOME/local && make && make install $ cd ~ $ cp local/bin/eruby public_html/cgi-bin/eruby
Now that you have both a development computer and a web host environment that supports eRuby you can start taking advantage of the Ruby language. Let's go through a simple web application just to get a taste of what Ruby provides. A demo can be found here.
<html>
<head>
<title>Welcome to eruby Test</title>
</head>
<body>
<h2>eRuby test</h2>
<%
# Require the CGI library
require 'cgi'
# New CGI object
cgi = CGI.new
# prepare trap for form variables
# there is an artifact space sent from an empty form field so to verify the field values have to be
# Stripped of whitespace and carriage returns (strip) so (empty) will work properly.
username = cgi['username'].strip
profession = cgi['profession'].strip
%>
<form method="post">
Please enter your username: <input type="text" name="username"><br>
Please enter your profession: <input type="text" name="profession"><br>
<input type="submit" value="Send">
</form>
<% if username.empty? # Print out the form asking for the username %>
<p>Please test my first Ruby web application by entering your name in the text box.</p>
<% else %>
Thanks, <%= username %>!<br>
<% if profession.empty? %>
<p>So you are unemployed? Don't worry learn Ruby and you will have a job in no time.</p>
<% else %>
<p><%= profession %> sounds like a fun profession.</p>
<% end %>
<% end %>
</body>
</html>
IIS on Windows XP
tutorials:
Ruby one-click installer
Get it from here:
http://rubyforge.org/frs/?group_id=167
eRuby
If you are a wiz at using minGW or another windows compiler tool you can compile eruby yourself using the sources at http://modruby.net/ current: eruby-1.0.5.tar.gz a
pre-compiled binary can be found at the any of the minGW mirrors:
Windows zip file
unix style compressed file
eruby.cgi
Getting this file can be a bit difficult if you do not have ssh access to your Linux server. You can also request that your web host copy it to your domain root or directory that you will be using eRuby. I have tried downloading add upload this file but this method is not dependable. The file is binary and very sensitive to changes in placement.
Happy Publishing!
What permissions or access rights do users need to use Ruby. Would users that don’t have full admin rights be able to use it. We are thinking about using Ruby to teach programming in school.
Ken
The Ruby language is open to use under its own license and is also covered by the GPL. For more information check the wikipedia page
great help. i had lot of probs starting ruby on IIS but this little note made things working for me. thx a lot !!
I echo the previous comment. You supplied exactly what I needed. Part of the challenge of Ruby is selecting the appropriate tool from several that do the same thing. Although I eventually want to get to Rails, I first wanted to do something on IIS that was simpler and fast. Your description of eRuby is just the ticket.
Hello,
I’ve followed the instructions on this page and I’m sure I’m missing something. The sample script for “hello world” just seems to hang? I’m running windows 2003 server.
Please email me to wscholar@getabby.com or post back here.
Thanks,
Wayne Scholar
Windows 2003 Server has much higher security settings than Windows 2000. Check these settings. Also I have noticed that a stripped down gaming verison of 2003 has become popular. If you are using something like this then a critical piece of IIS may be locked or missing.
you can got the infomation in “HTTP Error 404 - File or Directory not found” error message when you request dynamic content with IIS 6.0
http://support.microsoft.com/kb/315122/en-us/
ur site is superb.thanks to u all.
u code to run ruby in iis is
very helpful for me.
thanks