I have a scenario where I need to dynamically create classes from
existing application (external to app) databases, to pull data for
reports.
# Table definitions
APP_TABLES = %w(#list of tables for a given app - I'm sure I could
query this on a simple connect. But let's stick to this for now.)
APP_TABLES.each do |table_name|
# camelize for class creation
class_name = table_name.camelize
klass = Class.new(App) # uses App class to establish_connection to
externalDB
klass = class_eval do
#unsure about this. I need to set table_name to same as class name
ActiveRecord::Base.set_table_name("#{class_name}")
ActiveRecord::Base.const_set(constant_name, klass)
end # class_eval
# After creating the class - I want to establish an instance - but it
says that the class does not exist - more specifically constant doesn't
exist.
eval("#{table_name} = #{class_name}.new")
I would love to hear thoughts on this, especially if I'm approaching
this incorrectly.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.