Softies on Rails » Using ActiveSupport in your irb sessions

Rails expects your class names and table names to follow certain conventions. One of these is that your table name is always plural, and the model class is singular. Usually this pretty obvious:


# Table name: buckets

class Bucket < ActiveRecord::Base

...

end

But sometimes I forget how to handle the strange cases. I wanted my class to be named CardStatus. What do I call the table? If I already have a Rails app handy, I can start up script/console and find out:


myapp$ script/console

>> "CardStatus".tableize
=> "card_statuses"

If for some reason you want do this outside of the rails environment, just load the ActiveSupport gem first. Here's my irb session:


myapp$ irb

>> require 'rubygems'
=> false
>> gem 'activesupport'
=> true
>> require 'active_support'
=> true

I got false from the require rubygems line because I forgot that my irb autoloads rubygems anyway. It would return true if it wasn't alrady loaded.

Now that ActiveSupport is up and running, my irb session continues just like it did in script/console:


>> "CardStatus".tableize
=> "card_statuses"