Basically I need to connect to another app’s database, I’ve done the connection in config/database.yml, that database is not from a rails app so for starters the table names are not pluralized and also I’d need to add the establish_connection to all of them, I tried to create a parent class and Inherit the others from it but I just can’t get it right, keeps complaigning that the parent one doesn’t have a table, if i add abstract_class to it then the child modules are abstract as well -.-
How can DRY it up a bit
Update
This worked …
class QB < ActiveRecord::Base
self.abstract_class = true
establish_connection 'quickbooks'
def self.pluralize_table_names
false
end
end
not quite sure why the pluralize_table_names had to be that way, but it works, thanks for the hint on the abstract_class @zetetic
Update
Used this in the parent class, better for my case
def self.table_name
self.name.gsub(/QB::/,'').downcase
end
This should not be the case.
self.abstract_class = truesets an instance variable in the class singleton, a ‘class instance variable’. This is not shared by subclasses:This Martin Fowler blog post describes what is going on in more detail.