# encoding: utf-8
class MultiTable < ActiveRecord::Base
belongs_to :user
validates_presence_of :code, :name
end
# Define classes dynamically
%w(Agreement
Skill
Level).each do |klass_name|
# This can be done on the MultiTable class also
klass = Class.new(MultiTable) do
define_method :to_s do
"#{ code } #{ name }"
end
end
Object.const_set(klass_name, klass)
end
E para não ter problemas de carregamento destas classes geradas dinamicamente basta adicionar um arquivo no config/initializers/multi_table.rb
# config/initializers/multi_table.rb
MultiTable