Sneaking Rails through the (Legacy) system

Reading time: ~1 min ❓Shorter than a Rails console boot time

I’ll be posting stuff in the next few days about acts_as_legacy. For those not at Canada on Rails. I announced a small project that I’m going to be working on.

Acts as Legacy!

Here are my slides… up til I tried to do a live demo. ;-)

# Inventory model
class Inventory < ActiveRecord::Base
  acts_as_legacy :table_name => 'inventory',
                 :primary_key => 'prod_id',
  
  has_one :product, :foreign_key => self.primary_key
  
  column_alias :quan_in_stock, :stock
            
end   

Let’s try something a little different…

# SalesPerson model
class SalesPerson < ActiveRecord::Base
  acts_as_legacy :table_name => 'sales_person',
                 :primary_key 'sales_p_id',
                 :column_alias => 'sales_p_'
                 
  validates_presence_of( :name, :email, :phone ) 
end

# usage....
SalesPerson.find( 7 ).sales_p_name
=> 'Nigel'
SalesPerson.find( 7 ).name
=> 'Nigel'

The Slideshow

…Jeremy posted his slides as well. :-)

Hi, I'm Robby.

Robby Russell

I run Planet Argon, where we help organizations keep their Ruby on Rails apps maintainable—so they don't have to start over. I created Oh My Zsh to make developers more efficient and host both the On Rails and Maintainable.fm podcasts to explore what it takes to build software that lasts.