Dark Moon Velvet


First, you need ruby!

Open your command-line, first thing to do is update gems. On unix systems you can prefix the following with sudo if you do not have the permissions.

gem update --system

Then install rails type in:

gem install rails --include-dependencies

Creating a RoR project

Done? Create a folder somewhere, in the rest of the post I’m going to use D:/Test/2009-04/. To create a rails project you simply need to type rails followed by the name of the project, for example to create a project darkmoon configured for a mysql database:

cd d:\Test\2009-04\
rails -d mysql darkmoon

To test some basic functionality, run the WEBrick server:

cd darkmoon/
ruby script/server

On a unix box the last line should read ./script/server/

Go to http://localhost:3000/, if you see the rails welcome page all is well.


Your database configuration is located in config/database.yml. Default values are usually what you need if you do not run some exhotic configuration.

You should make sure your database driver is available, if you are not you will need to instal them, for example:

cd d:\Test\2009-04\darkmoon\
gem install mysql

Your database configuration file is located in config/database.yml. Often for testing, the dafaults should do nicely.

To setup the database:

cd d:\Test\2009-04\darkmoon\
rake db:create:all
Tags: , ,

Short summary

  • Apache’s <Directory /> needs to read Options Indexes FollowSymLinks +ExecCGI
  • Ruby cgi scripts need to have #!C:/path/to/ruby/bin/ruby.exe on Windows or #!/usr/bin/ruby for unix systems.

From the basics

Install wamp, just because its fast, simple, easy and stupid. Done? ok start it! You should see a little icon notication in your taskbar (near the clock). Click it! You should now see a set of menus, these are all shortcuts to whichever little thing you shall ever need (well, almost).

Now, to run a cgi script you will need to set up apache for it. Simply click Wamp, go to Apache, then httpd.conf. This will probably open it in notepad, if you do not have anything better setup. Press Ctrl+F and search for the following: <Directory. Found it? if not go to the top and click on the first line (notepad search is pretty stupid). If you are not following this tutorial using Wamp then this is probably the place you should edit, but since this is wamp its just slightly more... Wamp sets up its own special directory structure, so search again for <Directory and you should find something like (depending on where you installed wamp). These settings override the non specific ones so when using wamp or if you have something similar set up, edit here.

The alterations are relatively simple, simply, where it says Options make sure it says Options Indexes FollowSymLinks +ExecCGI.

Search for AddHandler cgi-script .cgi (it should be commented out, uncomment it by removing the sharp sign in front). then add a extra .rb at the end so it reads AddHandler cgi-script .cgi .rb

All done.

Optionally, you can search for DirectoryIndex and add index.rb to the list of files so that apache can auto execute them.

Now for some ruby scripting

Depending on the system your are using the first line will differ slightly, but in more or less it means the same ("execute the script using this"). For mac/unix systems type something like #!/usr/bin/ruby, while on windows it is: #!C:/path/to/ruby/bin/ruby.exe. Next type in your code, here's a sample snippet:

puts "Content-Type: text/html"
puts "<html><body>"
puts "<p>Congratiolations on completing the intro.</p>"
puts "</body></html>"

This was meant for ruby. But, replace ruby references to Python etc and you get the same effect.

Tags: , , ,

Time to start blogging.

.hello { word: out-there; }