Tuesday, December 2, 2008

Rails 2.2 - undefined method 'write_inheritable_attribute'

After installing Rails 2.2, I got what appears to be a common problem, where write_inheritable_attribute is no longer found.

$ rails test
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/bin/../lib/rails_generator/options.rb:32:in `default_options': undefined method `write_inheritable_attribute' for Rails::Generator::Base:Class (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/rails-2.2.2/bin/../lib/rails_generator/base.rb:90
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/lib/ruby/gems/1.8/gems/rails-2.2.2/bin/../lib/rails_generator.rb:34
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/lib/ruby/gems/1.8/gems/rails-2.2.2/bin/rails:13
from /usr/bin/rails:19:in `load'
from /usr/bin/rails:19

But this is clearly defined in activesupport-2.2.2. If you encounter this problem, check to see if you can load activesupport in irb:

$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'activesupport'
LoadError: no such file to load -- iconv
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/inflector.rb:3
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support.rb:26
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/activesupport.rb:1
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from (irb):2


If you see "LoadError: no such file to load -- iconv" your problem is a missing libiconv, which supports internationalization in Rails 2.2.

The rails wiki has the instructions on how to install and build iconv if you need them.

Hope this helps....

Update: For Debian, I got the same error, but had a different solution.

4 comments:

Anonymous said...

if your using Ruby Enterprise you will not get the iconv error as noted above but sure enough it is a missing iconv problem.

refer to this post if your using ruby enterprise
http://groups.google.com/group/emm-ruby/browse_thread/thread/e4aa78aa9c1e4c9d

sprewell said...

I just wasted hours on this so here's some more info. Active Support relies on iconv but if you load Active Record without incov installed, it will silently fail and tell you it couldn't find cattr_accessor, which is part of Active Support. The solution is to make sure iconv is installed. Unfortunately, because of a packaging mistake, it appears that ruby 1.8.7 doesn't come with iconv. You may need to install a stable snapshot to get iconv with ruby 1.8.7. Also, if you have ruby 1.8.6 installed on FreeBSD, you need to install iconv separately through the converters/ruby-iconv port.

Jeff Schmitz said...

Thanks Sprewell. This is great info.

Anonymous said...

Install the ruby-iconv port... it is required for the 2.0+ activerecord gem.

#package (if available)
pkg_add -r ruby-iconv

- or -

#port tree
/usr/port/converters/ruby-iconv/ make clean install