May 23, 2012No Comments

Rails ActiveModel and Localization

In Ruby on Rails 3, non-database functionality was moved from ActiveRecord to ActiveModel. This is great since it makes it easy to use all the ActiveRecord niceness we’ve come to love for non-ActiveRecord models.

My favorite bit of functionality moved to ActiveModel is localization. (Well, validations are actually my favorite, but localization is a close second.) Rails has robust localization support though the Rails Internationalization (I18n) API. Hopefully you’re already using it, if not for creating multi-lingual sites, then at least for keeping custom attribute and model names consistent between labels, errors messages, etc.

The Rails guide does a great job of walking us through the basics of localization and using it with an ActiveRecord object, but falls short when looking at ActiveModel localization. So let’s dive in…

Let’s say we have the following namespaced model:

[ruby]
module PetShop
class Puppy
include ActiveModel::Conversion
include ActiveModel::AttributeMethods
include ActiveModel::Validations

attr_accessor :name, :price, :image_url
end
end
[/ruby]

As you can see, we’ve already included some ActiveModel modules. Conversion gives us useful methods including to_param and to_key. AttributeMethods gives us lots of accessor and attribute related goodness. And Validations gives us, well, validations.

Let's look at the attributes. The "name" and "price" attributes will humanize nicely to "Name" and "Price" but I want to refer to "image_url" as "Puppy Pic", not the default humanization "Image Url". This looks like a job for localization!

Read more

May 3, 2012No Comments

Enter the Deepworld

Mike Laurence and I have been building web applications for a long time, and we’ve had the opportunity over the last year to work with Table XI on some fantastic web applications for our clients. The web offers a wide variety of challenges, but we always found scaling to be the most interesting. Things like cloud provisioning, load balancing, caching, and database replication make big projects a worthy challenge.

Sometimes you need a break from the web, though, so we decided to put our architecture skills to the test and build a massively-multiplayer adventure game: Deepworld.

Deepworld features an online, persistent sandbox universe; anyone can jump in to explore, build, or just hang out with friends. It's very engaging, and also the most technically complicated setup we've ever dealt with. We have dozens (soon to be hundreds) of worlds, all hosted across multiple cloud servers, with things like MongoDB, Redis, and various helper apps in the background.

We opted early on to use Ruby to develop our server code—an odd choice to many in the game industry, but something we are very familiar with. It turns out that EventMachine, the very mature Ruby equivalent of Node.js, is quite fast. With it, we've designed our own TCP-based protcol, baking in compression, authentication, and tons of other bells and whistles, as well as TCP testing framework on top of RSpec.

We’re in alpha testing phase right now, with a bunch of regular players in the alpha program. They’ve been building an amazing array of structures and are having an awesome time. We also recently held a Table XI playtesting party, which was great fun!

We've launched a Deepworld Kickstarter to help us with our final fundraising push, and have just under two weeks to go. Check it out for more info, thanks for your support, and hopefully we'll see you in the game!

Want to start visualizing your project risks?  Download our free Software Risk Management template

GoodFirms Badge