How to implement status codes in DB and Rails

You can use a state pattern for this and it works out pretty clean. There is also the acts_as_state_machine plugin you may want to check out. But here is a simple example of the state pattern used in credit card settlements.

# id :integer(11) not null, primary key
# name :string(80) default(), not null
# description :text

class SettlementState < ActiveRecord::Base
   has_many :settlements,
            :order => ''

class Settlement < ActiveRecord::Base

   belongs_to :settlement_state
   belongs_to :ledger

   validates_presence_of :xaction
   validates_presence_of :message

   def authorized
     self.settlement_state = SettlementState.find_by_name('authorized')

   def captured
     self.settlement_state = SettlementState.find_by_name('captured')

   def voided
     self.settlement_state = SettlementState.find_by_name('voided')

   def credited
     self.settlement_state = SettlementState.find_by_name('credited')

   def errored
     self.settlement_state = SettlementState.find_by_name('errored')

   def settled
     self.settlement_state = SettlementState.find_by_name('settled')

   def is_authorized? == 'authorized'

   def is_captured? == 'captured'

   def is_voided? == 'voided'

   def is_credited? == 'credited'

   def is_errored? == 'errored'

   def is_settled? == 'settled'

-- Ezra Zygmuntowicz-- Lead Rails Evangelist
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)