views:

14

answers:

3

I'm running ruby on Mac OSX 10.6.4, using Ruby 1.8 and activerecord 2.3.8. I'm running the following code inside of NetBeans 6.9 but I'm using the ruby interpreter from 10.6

I have the following code:

require 'rubygems'
require 'active_record'

ActiveRecord::Base.establish_connection
(
    :adapter=> "mysql",
    :host => "localhost",
    :username => "test",
)

class Test_information < ActiveRecord::Base
  set_table_name = "test_information"
end

record = Test_information.find(:first)

When the code runs I get an error that it can't find the table test_informations. There is a table called test_information and I can query it...but not with activerecord.

Is there some magic incantation that I have to use with set_table_name? I was under the impression that it was pretty straightforward to use an existing schema with activerecord...

Any ideas?

Thanks in advance,

--Robert

+2  A: 

The syntax is set_table_name "test_information" (no equals sign)

The Who
Doh! Pays to think a little more...Thanks again for you help.
RMatthews
+2  A: 

set_table_name is a method so you need to say

set_table_name "test_information"

Pass as parameter not as an assignment

bjg
A: 

Interesting...if I include either of the following lines after the class definition it works great.

Test_Information.pluralize_table_names = false
Test_Information.set_table_name("test_information")

Is there some reason why it doesn't work inside the class definition?

RMatthews