Forum: Ruby ActiveRecord class for multiple tables

Posted by Rob Marshall (rjmarshall17)
on 2013-01-28 18:11
Hi,

I assume that this has been answered, I just haven't been able to find
it...I have a database with a 10 tables named: data_table_00 through
data_table_09. They are all identical and I'm new to Ruby and trying to
figure out the best way, using ActiveRecord, to define the class. I
would like to be able to specify the table number at initialization.

I have done:

irb> class DataTable < ActiveRecord::Base
irb> end

Then:

irb> dt0 = DataTable.set_table_name 'data_table_00'

And that seems to work - of course irb gives me lots of output...but
we'll skip that part. But I was just wondering if there's a "cleaner"
way to do this.

Thanks,

Rob
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.