Friday, 12 December 2008

Ruby 1.9 and Active Record

I'm trying to use ActiveRecord outside of Rails and with Ruby 1.9. I kept getting an error

/opt/local/lib/ruby1.9/gems/1.9.1/gems
        /activerecord-2.2.2/lib/active_record/base.rb:394:in `<class:Base>': 
        undefined method `cattr_accessor' for ActiveRecord::Base:Class 
        (NoMethodError)
	from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-
        2.2.2/lib/active_record/base.rb:391:in 
        `<module:ActiveRecord>'
	from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-           
        2.2.2/lib/active_record/base.rb:4:
        in `<top (required)>'
	from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-
        2.2.2/lib/active_record.rb:34:
        in `require'
	from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-
        2.2.2/lib/active_record.rb:34:
        in `<top (required)>'
	from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-
        2.2.2/lib/activerecord.rb:1
        :in `require'
	from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-
        2.2.2/lib/activerecord.rb:1:
        in `<top (required)>'
	from SimpleTest.rb:2:in `require'
	from SimpleTest.rb:2:in `
'

so and undefined method cattr_accessor in ActiveRecord::Base.

Trying the same code in 1.8 worked fine. After much searching I discovered that ActiveSupport had to be installed. This looked like it was installed when I installed ActiveRecord, but it possibly wasn't a complete install.

so after a

sudo gem install ActiveSupprt

I'm good to go

Posted by kevin at 11:51 AM in Ruby

 

[Trackback URL for this entry]

Your comment:

SCode: (*) Generate another code
SCode

Please enter the code as seen in the image above to post your comment.

(not displayed)
 
 
 

Live Comment Preview:

 
« December »
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031