Okay...
So to do this, you need to understand meta-programming to a degree because that's what you're doing.
In normal Rails, you'd create a model as part of the development process, but what you're doing is creating some code that creates models itself (ie one level of abstraction higher than normal).
The equivalent straight ruby comparison is: (compare 1, with 2, below):
1. Creating a class (this is normal programming)
class Cat
def hi
puts 'meow'
end
end
You can then create new Cat objects like this:
furrycat = Cat.new
and make it meow like this:
furrycat.hi
2. Creating a piece of code that creates a class (this is meta-programming)
a_class = Class.new
hi_method_block = Proc.new{ puts 'meow' }
a_class.send(:define_method, :hi, &hi_method_block)
You can then create new "Cat" objects like this:
and make it meow like this:
furrycat.hi
---
So... assuming you followed that, then you'll understand that you could do the same thing with ActiveRecord::Base classes, which is what forms the bases for Active Record model classes. This is how you'd dynamically LOAD one of your programmatically generated models. Creating the table is just a matter of executing some arbitrary SQL which can be built using ActiveRecord::Base.connection.execute. (Eg to run a count of a fictitious users table, you'd do this: ActiveRecord::Base.connection.execute("SELECT COUNT(*) FROM users;")
However, like I said, there's no point trying to do this until you can walk, because this really is running. Most Rails devs hardly ever get into this stuff. I've been a Rails developer since 2005, and I've only done this sort of dynamic table and database thing once or twice in practice.
Julian