Vain Routes – A Rails Engine

You didn’t invest all that time into creating your beautiful restful routes only to have them displayed in a console window, did you?

Introducing ‘Vain Routes’ – a rails engine that enables you to view your routes directly from your browser, sort them, and even filter them! While the command line may helpful, it isn’t as pretty as this!


  • Clean User Inteface to view your routes as html
  • Sort your routes by verb, path, controller or action
    Sort Routes
  • Filter routes by keywords
    Filter Routes
  • A rails 3 engine which is installed and running in under a minute!

gem install 'vain_routes'

Update your Gemfile:

 group :development do
   gem 'vain_routes'

Launch your Server

 rails server

Open your browser to: http://localhost:3000/vain/routes

ruby-oci8 & SELinux

LoadError: /opt/oracle/instantclient_10_2/ cannot restore segment prot after reloc: Permission denied - /usr/local/ruby192p0/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.0.3/lib/
from :29:in `require'
from :29:in `require'
from /usr/local/ruby192p0/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.0.3/lib/oci8.rb:23:in `'
from :33:in `require'
from :33:in `rescue in require'
from :29:in `require'
from (irb):1
from /usr/local/ruby/bin/irb:12:in `'

/ cannot restore segment prot after

If you encounter an error like above, the problem very well could be the SELinux (Security Enhanced Linux) conf setting.   We ran into this issue trying to use ruby-oci8 in our rails application.  It was working on one CentOS VM we built, but not on another coworkers.  After painstakingly taking things apart, it turns out the difference between the two virtual machine instances was that the ‘getenforce’ command returned ‘Disabled’ on one and ‘Enforcing’ on another.

A quick ‘setenforce 0’ will enable you to test out if this fixes your issue.  However be warned that to disable it so that it doesn’t come back after restarting, you must modify the ‘/etc/selinux/config’ to disable it permanently.   GL!

Webrick serving Rails 2.3.x over SSL

Just a couple days ago, I encountered an issue with having to serve a rails app over SSL from a local development environment.  Unfortunately the localhost was a windows machine, so using passenger wasn’t much of a choice.  I found several good articles talking about how to do this, however they didn’t work for me.  The one that got me the closeset was from a post at (thanks Keith!).

I believe the issue I had was that the articles I was referencing were nearly a year old, and probably used an older version of rails.  I took a look at the server script that others proposed, vs the latest server.rb file (and hence rails’ server command.rb file) that is used in 2.3.x rails applications; and I believe the difference comes down to the changes in rails’ underpinnings to being rack based and how the webrick server & rails envirionment is setup and configured.

I first cracked open the ‘script/console.rb’  file from my app:

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'

Turns out that, it isn’t too helpful, as the bulk of the logic exists somewhere else. Turns out if you freeze your rails gems, it’s in: ‘vendor/rails/railties/lib/commands/server.rb’. If you don’t freeze your gems, it’ll be in: $GEMS_HOME/gems/rails-2.3.x/lib/commands. This file’s a bit large to post here, but for discussion’s sake here’s a link to it on github.

After reviewing the file, I found I needed to add values into the options hash, but there didn’t seem an easy way to make that happen.  Since I was short on time, I took the path of least resistance 🙂 – I copied commands/server.rb and created a file in scirpts/ssl_server.rb.  For reference, here is a copy of the ssl_server script file I am running.

There are three notable changes I made:

  • Modified port to be 443 (to simplify testing)
  • Added options values for SSLEnable, SSLVerifyClient, SSLCertName
  • Removed block that determines server and forces the use of webrick

One last thing to note, in our scenario we needed to have mixed traffic over both 80 and 443.  In order to accomplish this, I borrowed a suggestion from the 81electric blog, and ran both the ssl_server and standard server scripts at the same time – maybe not elegant, but simple!

Extending a Plugin within rails

Image by

Image by kqedquest

Have you ever wanted to add a method to a class that belonged to a plugin? Well the other day while I was working on, I found myself in that position. I am using the acts_as_taggable_on plugin and wanted to memoize a call I was making a lot in various outputs:
<%= =>
This is one of those problems I could have solved several ways:

  • Focus on normalizing the data on input
  • Use a helper to accomplish the same goal
  • Cache the page/partial output
  • Not worry about it at all, as this is probably not worth the performance gains per effort invested (at the moment I’m sure there’s plenty more I can optimize)

However it was more out of curiosity that I pursued solving it the way that I initially set out to do.   My first attempt was simply creating a class of the same name in my models folder, but that didn’t have the effect I wanted as (I believe) because the way rails loads classes, it overwrote the class definition instead of adding to it.

At this point I knew there had to be a better way than just modifying the code in the vendor/plugins folder.   Turns out the solution is to add the class/file in the initializers folder as that is the correct time to augment the class during rails initialization.  In hindsight,  pretty obvious.  However since I’m not familiar with the underlying mechanisms of rails as much as I’d like to be, I think I’ve generally overlooked the initializers folder.