Specials

Home > Specials > Columns

Pimp My Rails

walski on 03/26/2008 11.24 AM
(read 3756 times)

Sex up your MMOG development with Ruby on Rails! We invited Thorben from Team Fetmab to tell us more about this framework and the simplicity of working with it. Over the next couple of weeks he will not only show us how to create a simple RPG from scratch, but also provide some background information on the Rails scene.

Kicking the tires

Hey folks and welcome to the "Rails for MMOGs" tutorial. In the next few weeks we'll show you how easy it can be to develop a MMOG with Ruby on Rails, the rising star of the web development community in the past three years.

Like many of you, we're coming from a PHP background, but at the end of 2006 we felt like this wasn't the best way to develop web applications and experimented a lot with different approaches. Back in these days Rails was already a well known framework and the first hype was over. So actually we were a little late to the party, but maybe this came in very handy as we were not totally blinded by the hype but got in touch with Rails with some serious concerns.

But we kept going, and over time we came to love many of the unfamiliar concepts, that Ruby is offering and today we're very glad, that we didn't went back to PHP after the first shock of how different Ruby and Rails are.

Don't get me wrong, I don't think Rails is THE solution to all your trouble, pain and suffering. But it's a very good solution for us and I think, no matter if you continue coding your common language or do the switch to Rails, it's good to know "The Rails Way".

The Rails Way
Beside the description of the spirit of development with Rails "The Rails Way" is a very good reference book by Obie Fernandez, a Rails expert, very well known in the Rails community. If you're looking for some kind of Rails reference, check this out.

Ok, enough said about us, but just a few words about this tutorial.

What we can offer and what we can't

Unfortunately things changed a little bit since we first talked with Galaxy-News about this tutorial. We ran into some serious timing problems, caused by the opportunity I've got at university to catch up a course of lasts semester, which gives me the possibility to transfer to a college in the USA next year. Long things short: I had to learn and write a lot in the last week to achieve this goal and was really lacking time to keep the Trans 'n Porter development going and write up this tutorial. So I've to get this done far quicker, as I would like to have, but I'll try to turn this constraint in the opposite: All over the tutorial I'll explain everything which is necessary to get a MMOG in Rails up and running. From the very start, to the deployment on your server. But whenever I feel like I should go more into detail about features or concepts I'll just give you a reference to some of the excellent Ruby or Rails blogs out there which cover exactly this topic. So if you think it might be interesting just follow those references. This is good for another reason: You can explore the Ruby/Rails blogosphere which is definitely a good idea. It's a great source of explanation and inspiration and most of the references I'll give you are certainly far better explained then I ever could.

Alright. The time wasting introduction is over, I just wanted to have this cleared out before we start, but now let's get into the exciting part!

Installing

Generally there are two options to get started with Rails:

  1. Install all you need on your computer
  2. Use Heroku, an environment which allows you to create whole Rails applications in your browser! It's not quite the best solution for large projects but it's very well suited to make your first steps. The downside: It's currently in an invite-only beta phase so you can't just read this tutorial, register your account and start coding. But if you would like to test Heroku just leave a note in the comments, I'll send you an invite.
So here is a short overview of how you can get Rails running on the platform of your choice. Basically all you need is Ruby and RubyGems. The latter is used to install Rails with just one command, later on and on all platforms in the same, easy way. So even if there are stacks out there, that containing everything from Rails to MySQL and offer installers as well ( InstantRails, RubyStack), we will take the RubyGem approach because this way you don't depend on the maintainers of these stacks and can easily update to the newest Rails version as soon as it is available. So what does it need, to install Ruby and RubyGems?

 

Installing Ruby and RubyGems

Windows

I've never installed Rails on Windows so all this can be considered hearsay ;) To get thing going fast, we use a stack which bundles Ruby, RubyGems and a simple editor with syntax highlighting for Ruby. Yes, this is a stack too, but it's, unlike the Rails stacks mentioned above, a really lightweight one and ships with the things we need, but nothing more. So just download and run the Ruby One-Click Installer. Be sure to have the "Enable RubyGems" and "European Keyboard" check-box checked at the installation. That's it. Read on for the instruction on how to install Rails below.

Ubuntu Linux

Nearly nothing to do:

  1. Install Ruby and RubyGems via apt:

sudo apt-get install ruby rubygems

Mac OS X

Mac OS X Tiger shipped with Ruby already, Leopard now ships even with Rails! But to stay up-to-date we'll install a version of rails manually. So either follow this tutorial which guides you through the long way of compiling all of Ruby and Rails yourself, or if you have installed MacPorts you can install the packages ruby and rb-rubygems and if you think that is too much of an effort as well, just try this one-click Ruby stack for Mac OS X. It ships, like the Windows installer with RubyGems, so you don't need to install that by hand.

Terminal
  • On Windows:
    1. Hit Win+R
    2. Type in cmd
    3. Execute that
    4. Done, terminal window should open
  • On a Mac:
    1. Go to the Applications/Utilities folder
    2. Open the Terminal application
  • On Linux:
    • Ok... you should know how to do that

Installing Rails

First be sure, that you've the newest version of RubyGems. Just open up a terminal and execute

gem update --system

On any Unix like system like Linux or Mac OS X be sure, that you execute all gem actions as a superuser. Just try this

sudo gem update --system

on such systems.

Now the exciting part: Rails is coming to your computer... YAY!

gem install rails

At this point you should go cooking or do your daily workout or whatever: it will take a while! But attention, maybe you will need to accept on installing depending software during the installation. Just press y when asked to do so by gem.

The first Rails application

After you've managed the installation it's definitively time to kick your first Rails application out of the door. Unlike PHP, Rails is not only a language, it's a framework for your web application. And unlike frameworks in other languages, "framework" for Rails doesn't just mean the power of some libraries which you can use. The first thing of the Rails framework you will be faced to is the Rails Generator. If you would like to test a PHP environment you would just generate a very short test.php, put it somewhere where your web server can interpret it, check this file in the browser and you're done. Rails works differently. Any Rails application starts with the call of the simple command rails. This will create a directory structure and the basic files of a Rails application for you. Let's test it.

Heroku

Heroku users can't use all these command line scripts. But they have some nice screencasts which guides you through nearly any feature that they're offering. You can see how to create a new application on this one.

All the other screencasts can be found here.

Just open up a terminal again, head to some directory where you would like to create your first test application and then type in

rails test_application

You will see how the rails command creates the application, afterwards. If this is done just change into the newly created test_application directory and now type

ruby script/server

and wait while WEBrick, a small web server which ships with Rails starts up your newly created application. When it's done, head over to your browser and visit: http://localhost:3000. You should see a Rails welcome screen which is somehow the equivalent to the phpinfo() function of PHP.

Congratulations! Your first Rails application is up and running ;)

Next episode

In the next episode I'll show you how easy it is to realize a user authentication system with Rails and we'll start with the first pieces of our tutorial RPG "Solid Sword".

I would be glad if you would leave your critics, wishes and suggestions on how to improve this tutorial in the comments.

See you next week,

Thorben

P.S. We thankful acknowledge the logo design by boboroshi.com

Web development with Ruby on Rails:

Pimp My Rails
Pimp My Rails: The Rails Framework
Pimp My Rails: The First Model
Rails Pimpin' Continues


Share   Subscribe

Comments

Advertisement
Astro Empires
Ondarun
Legendary Voyage
Cosmic Supremacy
Advertisement
How old are you?
< 18
18 - 24
25 - 34
35 - 49
> 50