Monday, November 28, 2011

Random Video Game Name Generator with Ruby

I've been working with a LOT of Javascript lately. And when I say "working with," what I mean is "finding scripts that will do what I want them to do and modifying as necessary." Wait, isn't this supposed to be a Ruby on Rails blog? What happened!?

I got back to work on my random video game name generator tonight. I basically wanted to style it a bit and find a way so that it would generate a new phrase whenever the page is reloaded and then provide a link to reload the page. Pretty easy to do with a Javascript code, but I'm not a huge fan of reloading the entire thing just to reload this bit of text. Probably a better way to handle this, right? Maybe an Ajax call? What do you guys suggest? This works but I don't like the look of it, I guess.

Anyway, here's a link to the app on Heroku:

Random Video Game Name Generator

I wanted to accomplish a few things with this project. First off, build a random name generator with Ruby, and then figure out how you run that code on the web. This was largely a matter of learning Sinatra, and when I say "learning," I mean reading a tutorial and talking to @jqr about it for a few minutes. Sinatra is like SO easy.

I've got plans for how I could expand it (don't I always? Other coders have this problem too, right?) such as allowing users to save names they especially like, then enter a short description of what the game would be like. Viewers could also look at games that had been saved, perhaps vote on them, look at most popular games, etc, etc.

I think it's getting easier for me to think about WHAT applications COULD do, now that I know a bit more about HOW they're built. That makes sense, right?


  1. Simplest way to refresh the page using JavaScript.

  2. You should check out the jQuery Air tutorial (and Rails for Zombies) at They are free and pretty damn good. By the way, where is the code for this? I don't see it on Github. Also, from viewing the source, you have a html document inside your html document.

    Keep up the good work! I may not always say it, but I'm always thinking it.

  3. @Eli awesome, I'll take a look at that code tonight! Might be simpler than the javascript I'm using now.

  4. @David Thanks for the encouragement! I definitely feel more productive when I'm blogging about coding on a regular basis, so I'm trying to keep that up, too.

    Looks like I haven't actually put the code on Git. I'll post it when I get home this evening.

    I've actually been planning to check into Rails for Zombies for a while now, so I'll take a look at both tutorials you mentioned (at some point)

  5. Hey, nice work, bro. One thing: You could save the page for linking w/o a db by providing the title as page param.

    If you wanted the name to be more of a surprise, you could encrypt (look for a 2 way encryption gem) the name param as well .