Ubuntu (Hardy): Install Apache 2 Server

Setting up Apache 2 server on Ubuntu Hardy is pretty easy.

sudo aptitude install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert


I choose apache2-mpm-prefork (single thread) over apache2-mpm-worker (multi-threaded requests). This is because mod_rails may work with apache2-mpm-worker, but is only currently tested to work with apache2-mpm-prefork.


Edit your apache configuration file:

$ vim /etc/apache2/apache2.conf

At the end of the file add the following:

ServerName your_server_name

And restart your server:

$ sudo apache2ctl graceful


If you get the following error when restarting Apache it means that you didn’t succeed in setting the ServerName:

apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName


Start your prefered browser and open your server ip address (e.g., you should see something like this:

It Works!

Or use curl (command line is always better):

$ curl

You should see:

<html><body><h1>It works!</h1></body></html>

It Works!!!

Ubuntu (Hardy): Install Apache 2 Server

Git: Creating a Remote Branch (and track it locally)

Required steps to create and track locally a remote branch with git:

# Create new remote branch
git push origin origin:refs/heads/new_branch_name
# Make sure everything is updated
git fetch origin
# Check your branch has been created
git branch -r
# Track a remote branch
git branch --track new_branch_name origin/new_branch_name
# Checkout remote branch
git checkout new_branch_name
Git: Creating a Remote Branch (and track it locally)

Gem: Simple Navigation (Navigation menu builder for Ruby on Rails)

I’ve just released my new gem simple_navigation. This gem help’s you to create a navigation menu for your Ruby on Rails application.


Edit your config/environment.rb to setup simple_navigation gem:

config.gem "mexpolk-simple_navigation",
    :lib => "simple_navigation",
    :source => "http://gems.github.com"

And from the command line, install the plugin:

rake gems:install


To create your menus create a new file named config/initializers/simple_navigation.rb like this:

SimpleNavigation::Builder.config do |map|
  map.navigation :default do |navigation|

    # Root menu without child elements (menus) that points to /dashboard
    navigation.menu :home, :url => { :controller => "home", :action => "index"}

    # Root menu with child menus without anchor link
    navigation.menu :contacts do |contacts|

      # Child menu with many possible urls (or many controllers and actions)
      contacts.menu :list, :url => { :controller => "contacts", :action => "index" } do |contact_list|

        # This menu will marked as current when you're on the following
        # controllers and actions (including the controller and action
        # specified in the :url option):
        contact_list.connect :controller => "contacts" # ...current on any action from this controller
        contact_list.connect :controller => "people", :except => "new"
        contact_list.connect :controller => "companies", :except => "new"


      # Another submenu that points to /person/new
      contacts.menu :new_person, :url => { :controller => "people", :action => "new" }

      # Another submenu that points to /company/new
      contacts.menu :new_company, :url => { :controller => "companies", :action => "new" }


    # Another root menu with nested submenus
    navigation.tab :admin, :url => { :controller => "users", :action => "index" } do |admin|
      admin.menu :users, :url => { :controller => "users", :action => "index" } do |users|
        users.menu :reports, :url => { :controller => "user_reports", :action => "index" } do |reports|
          reports.menu :activity, :url => { :controller => "user_reports", :action => "activity" }
          reports.menu :login_atempts, :url => { :controller => "user_reports", :action => "login_atempts" }
        users.menu :new_user, :url => { :controller => "users", :action => "new" }


Finally, to render you newly created menu called :default, in your default layout (layout/application.erb):

<%= simple_navigation :default %>

Ready for Internationalization (i18n)

If you want to use internationalization in your menus, set the option :i18n => true like this:

SimpleNavigation::Builder.config do |map|
  map.navigation :default, :i18n => true do |navigation|

And add to your config/locales files (e.g. es-MX.yml) the following:

    default:                          # The name of your navigation menu
      home:                           # The name of your root menu
        title: "Inicio"               # The translated title for your root menu
            title: "Panel de Control" # The title for index action child menu
            title: "Nueva Página"     # The title for new action child menu

Sample Application

I have a sample application at GitHub so you can see it work. This application has the following configuration (config/initializers/simple_navigation.rb):

SimpleNavigation::Builder.config do |map|
  map.navigation :default, :i18n => true do |navigation|
    navigation.menu :home, "Wellcome", :url => { :controller => "home", :action => "index" } do |home|
      home.menu :settings, "Appliction Settings", :url => { :controller => "home", :action => "settings"}
    navigation.menu :pages, :url => { :controller => "pages", :action => "index" } do |pages|
      pages.menu :page_one, "One", :url => { :controller => "pages", :action => "one" }
      pages.menu :page_two, "Two", :url => { :controller => "pages", :action => "two" }

When you render the navigation menu, it creates an unordered list like this:

<ul id="simple_navigation_default" class="simple_navigation" depth="0">
  <li id="simple_navigation_default_menus_home" class="menu" drop_down="true">
    <a href="/home">Wellcome</a>
    <ul id="simple_navigation_default_menus_home_menus" depth="1" style="display: none;">
      <li id="simple_navigation_default_menus_home_menus_settings" class="menu" drop_down="false">
        <a href="/home/settings">Appliction Settings</a>
  <li id="simple_navigation_default_menus_pages" class="menu current_child" drop_down="true">
    <a href="/pages">Pages</a>
    <ul id="simple_navigation_default_menus_pages_menus" depth="1" style="display: none;">
      <li id="simple_navigation_default_menus_pages_menus_page_one" class="menu" drop_down="false">
        <a href="/pages/one">One</a>
      <li id="simple_navigation_default_menus_pages_menus_page_two" class="menu current" drop_down="false">
        <a href="/pages/two">Two</a>

This result, with a little help of our friends CSS+Javascript will result in something like this:

Screenshot-Simple Navigation - Sample Application - Mozilla Firefox
Screenshot-Simple Navigation - Sample Application - Mozilla Firefox

Check the Simple Navigation Example yourself… Hope you enjoy it!

Gem: Simple Navigation (Navigation menu builder for Ruby on Rails)

Ruby: Convert Number to Words (Numerical)

Recently I’ve published my new gem NumberToWords. This plugin/gem will override Ruby’s Numeric class adding a new method called to_words. For now, it only works for Spanish.

Sample usage:

require 'rubygems'
require 'number_to_words'
=> cinco mil seiscientos setenta y ocho”

Another common usage is for describing currency quantities:

number = 4567.90
=> 4567.9
number.to_words.capitalize << ' pesos ' << (number.to_s.split('.')[1] || 0).rjust(2,'0')
=> "Cuatro mil quinientos sesenta y siete pesos 09/100 M.N."


Happy Hacking!

Ruby: Convert Number to Words (Numerical)