rails software

Fixing: undefined method `require_gem’ for main:Object (NoMethodError)

After upgrading to the newest version of rails (2.2.2) I was getting this error:

administrator@shuttle:~$ rails -v/usr/bin/rails:17: undefined method `require_gem' for main:Object (NoMethodError)

Anytime I called “rails” I would get this error and could not get past.

Here is the fix

administrator@shuttle:~/$ sudo vim /usr/bin/rails

Look for anywhere in the file that calls “require_gem”, I found it in only one spot:

require_gem 'rails', version

And change “require_gem” to just “gem” so:

gem 'rails', version

Save and when you run “rails -v” you should see this:

administrator@shuttle:~/$ rails -vRails 2.2.2

You should no longer get the error with running “rails”


Fixing: uninitialized constant Gem::GemRunner (NameError) – Ubuntu

After upgrading to the newest version of rails (2.2.2) I was getting this error:

administrator@shuttle:~/$ gem -v
/usr/bin/gem:10:Warning: Gem::manage_gems is deprecated and will be removed on or after March 2009.
/usr/bin/gem:23: uninitialized constant Gem::GemRunner (NameError)

Anytime I called “gem” I would get this error and could not get past.

Here is the fix

administrator@shuttle:~/$ sudo vim /usr/bin/gem

Change the top of the file to look like this:

require 'rubygems'
require 'rubygems/gem_runner'

Save and when you run this you should see this:

administrator@shuttle:~/$ gem -v

You should no longer get the error with running “gem”


Working with Blueprint: A CSS Framework

SimpleLog base installSo I decided to change my blogging software, from no software (Blogger) to SimpleLog. I setup everything up in my dev environment and it was by far the easiest setup I have seen so far. Took about 10 minutes including setting up the virtual hosts.

While getting super interested in my blog again I was looking for some nice examples of css blogs to get inspired I stumbled upon Blueprint, which is a css framework so I decided to give it a whirl.

First impressions it is super lightweight and non-intrusive, just two lines that have to be added. to the head which includes the style sheets. My only gripe so far was that they just include one grid option which is 14 columns, its not a big deal all that I think it needs is a few other background images to show the options of columns from the grid. Like 7 columns, 3×8×3 and so forth. in progressSo I hit up Photoshop and came up with a basic color scheme and outline for the new blog. Took about a day of going back and forth on how much I wanted to add to the site but being inspired by rails iterative approach to programming I decided to stick with the simple and expand from there.

Back to Blueprint, with my design it ended up being very easy to implement in blueprint. It doesn’t have anything nested tho which I was really interested in since it looked to handle nesting very gracefully. I tried as hard as I could to make this design fit into a 14 column grid but I made the design decision to keep the width at 780 instead of Blueprints default of 960. But not to fear we are just working with css here all I did was just override two of their default widths in my screen.css to keep the integrity of their files in case I decided to upgrade them in the future it will be fully degradable.

Their reset.css worked great, I am use to using Eric Meyers reset.css and then creating everything from there. But Blueprint had an unexpected typography.css which setup quite a bit of the default typography. Which was a huge time saver, because Eric’s just leaves you out in the cold to setup everything on your own which is totally cool if your project warrants it but sometimes there are elements that get introduced and have no control over.

SimpleLog + Blueprint BaseSo setting up a new template in SimpleLog was easy and I started editing the site.rhtml layout to use the naming conventions per Blueprint. Just a few class changes and I removed some default SimpleLog items that I didn’t include in my final design and boom! We have an outline!

Fast forward through time, 26 css declarations and 3 images later and my homepage was almost done. Time in total was about 2 hours to copy and setup an entire new template with SimpleLog and Blueprint. I was amazed, usually I hate when things try to be “smart” and assume they know what options and action you are going to preform but Blueprint didn’t get in my way at all. Since everything for the base elements was already setup I just used my ID’s and Classes to extend the base and life was good.

Although I was just concentrating on the homepage today flipping through all the other pages they didn’t look that bad by default. SimpleLog uses a lot of the same css names and conventions throughout their pages meshed with Blueprints base styles and my overrides the only things left to do were the specifics of the page.

Initial design for

Last but not least, my current host is not very Rails friendly so I am looking for a new host for my blog. While doing that I will continue to update here and work on the new version on my dev server. So far:

SimpleLog: A+

  • Ton of features and rock solid. Easy install and great documentation. I have not looked into any extensions or plugins yet but there are a few areas where I can see a few more helper functions. But for getting a blog up quick and painless SimpleLog is the way to go.
  • SimpleLog Website

Blueprint: A-

  • For just being at 0.3 release it is a huge time saver, its not just the resets for cross browser compatibility but it also includes a good typography and print styles which I have always been looking to create. I hate going through and trying to think of all the HTML elements a client could potentially use and make sure they are set accordingly. Blueprint defiantly has a future in my web development life and releasing it to the community will only make it better.
  • Blueprint CSS Framework Website

Understanding Rails Partials

Partial’s are great, i really wish there was something as straight forward in Smarty. With Smarty it would require a loop and an include, but partials roll that all into one. It great when you are displaying a list of items, especially if that list can be used in multiple pages in many contexts.

With PHP you would have to:

{include file='links.tpl' title='Newest links' links=$link_array}

Then in links.tpl do the loop:

<div id="box">
{foreach from=$links item=l}
.. do stuff ...

But Rails on the other hand if you pass a collection to a partial it automatically treats each item in the collection as an individual item and there is no need to create a loop it is done inheritly.


<%= render :partial => 'list_item', :collection => @customers %>


<tr class="<%= cycle('odd','even') %>">
<td><%= link_to list_item.last_name,
:controller => 'customer',
:action => 'show',
:id => %></td>
<td><%= list_item.first_name %></td>
<td><%= %>, <%= list_item.state %></td>

You may be thinking that it is really not much less work but writing loops all day long can get tiring especially when they are look the same and do the same thing. Partials take it to the next level and add a real intuitiveness to the loop because it is not just an array of items you are looping through it is actual objects a template is being rendered with.

Partials can also be used without the collection in just a basic include of a sub template the syntax is below. Useful but I have not found it as much fun.

<%= render :partial => "account", :locals => { :account => @buyer } %>

Starting a Rails Life

My rails life seems to be starting out similar to my php life. It all began with an internal application for my dad. He has a music instrument sales, rental and repair business and he initially did everything on paper to keep track of customers, instruments and billing. I took it upon myself to create a web based application for him to keep track of all of it. It was my first php application written in php3 and run on a small server here in the house. It is amazing that it is still running and he still uses it.

That was 7 years ago and looking back at the code now I cringe. Sometime in between there and now it was upgraded to php4 and it looks like that was a hack of a job. But since then my php life has expanded to the point of it no longer being a challenge. So what else would be a better way to start my Rails life than to revisit my dads billing application and recreate it with rails. Of course fixing all the issues with the current billing process and adding some additional features to make life easier.

To the right is a screen shot of the current functionality and design. I am currently just working on getting the layout squared away so functionality can be added without having to stop and think how it should look. So far only 56 lines of code have been written and about 4 hours have been spent on the project, 2.5 being spent coming up with a design and 1 hour spent implementing and tweaking it. So far rails has been a dream come true.

Coming from php which is mainly mirrored from C++ I have always been use to the long hand conditionals. One thing that rails offers is the “unless” command. Compacting an if statement into one line that can be read without much difficulty. Here is an example of its use, probably not the most efficient but I am sure it will get tweaked once more come into play.

<%= ' class="selected"' unless controller.controller_name != 'customer' %>