| home | forums |
resources |
search |
news | join | members: 6376 |
Hiveminds | Sat, 2007-08-18 16:43 tags: Tutorials, Web Developer, eRuby 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. Using Ruby on the webWhat is eRuby?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. About this tutorialIn 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. Setting up a development PCWindows IIS web serverIs 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. Ruby One-click installerThis 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. eruby.exe( for set up on the localhost)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. IIS configurationThis 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>
Setting up the shared host.htaccess support on your web hostTo 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 eruby.cgi ( for set up on the web host)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 ConclusionNow 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>ResourcesIIS on Windows XP Ruby one-click installer http://rubyforge.org/frs/?group_id=167 eRuby Windows zip file eruby.cgi
This article brought to you by the
Hiveminds Magazine - Staff. Contact us if you want to post an article or announcement anonymously |
PHP London Hotels
Joomla! Laptop Reviews
Silverlight Just Dial International Calls
Silverlight Excel Training Courses
Wordpress excel courses in london
Drupal Data Recovery
|
||||||
NewsletterGet updates on Hiveminds services, articles and downloads by signing up for the newsletter. |
Editor's choiceSome of the better articles, stories and tutorials found at Hiveminds. |
Find moreFind more of Hiveminds articles, stories, tutorials and user comments by searching. |
Picked linksHand picked websites and articles from around the web that provide quality reading. |