Link to home
Start Free TrialLog in
Avatar of TristinColby
TristinColby

asked on

Ruby ActiveRecord

I am trying to establish a connection then retrieve all the rows from a table. when i try to inherit from the ActiveRecord::Base, i get the following error: fixer.rb:14: superclass mismatch for class Data (TypeError).  Can anyone tell me what is wrong here?

require 'active_record'

ActiveRecord::Base.establish_connection(
    :adapter   => 'sqlserver',
    :host      => 'servername',
    :username  => 'login',
    :password  => 'pass',
    :database => 'db'
)
class Data < ActiveRecord::Base
end
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TristinColby
TristinColby

ASKER

ActiveRecord is defiantly installed.  ado.rb is present. and i've already tried. This is an existing table. Do i need to dump the schema first or something?

class Data < ActiveRecord::Base
    set_table_name 'Data'
    #set_primary_key 'ServiceID'
end

Doesn't work.
aHA! found a limitation.

your class name and set_table_name values can't be the same.

so

class Blah < ActiveRecord::Base
    #set_table_name 'Data'
    #set_primary_key 'ServiceID'
end

will work, but

class Data < ActiveRecord::Base
    set_table_name 'Data'
    #set_primary_key 'ServiceID'
end

Will Not.
does that mean your problem is solved now?

Yes