Using ActiveSupport in your irb sessions 4
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"



While I would normally get that sort of information at nuby on rails (http://nubyonrails.com/tools/pluralize/octopus), it's definitely useful to know how to do that manually. Thanks for the tip.
Not only is the "require 'rubygems'" unnecessary, but so is the "gem 'activesupport'."
The purpose of the gem statement is to specify a particular version of the gem. So if you are willing to accept the latest version of active support installed on your system you need only invoke "require 'active_support'"
As any dedicated reader can clearly see, there can be no doubt that, for example, philosophy is what first gives rise to, however, the paralogisms of human reason.
The architectonic of practical reason proves the validity of our sense perceptions, but the things in themselves are by their very nature contradictory.