Dear all
My ActiveRecord::Base is connected to server_a (local server), has a
Server model contains about 100 server records (remote server).
I use the following block to retrieve the server infomation. It works
fine.
Server.find_all_by_server_type(“sybase_t”).each do |s|
if s.server_name =~ /^LIS_..._ST1[0-2]/ and s.is_active?
class Order < ActiveRecord::Base
set_table_name = "orders"
end
Order.establish_connection s.connection_hash
begin
puts "#{s.server_name} has #{Order.count} orders"
rescue
puts "#{s.server_name} is down"
end
end
end
I want to create another model OrderDetail in the remote server (see
below code). It does not work. It said “TypeError: superclass mismatch
for class OrderDetail”.
Server.find_all_by_server_type(“sybase_t”).each do |s|
if s.server_name =~ /^LIS_…_ST1[0-2]/ and s.is_active?
class Order < ActiveRecord::Base
set_table_name = “orders”
end
Order.establish_connection s.connection_hash
class OrderDetail < ActiveRecord::Base
set_table_name = “order_detail”
end
OrderDetail.establish_connection s.connection_hash
begin
puts “#{s.server_name} has #{Order.count} orders and
#{OrderDetail.count} order_detail”
rescue
puts “#{s.server_name} is down”
end
end
end
I used google and find that the error will happen if the code like this
http://railsforum.com/viewtopic.php?id=10993
- class Cool
- end
- class SpecialCool < Cool
- end
- class SpecialCool # this line will raise an error
- end
How can I change my code so that I can have more than 1 models in the
remote server?
Thank you very much
Valentino