Updated 2026-06-17
This time, it took me around 8 working hours since the start of a new ruby-based project before I stumbled upon what seems to be a serious bug. The first time I tried to extend an association, activerecord failed with
associations.rb:1368:in `const_set': wrong constant name FooBar::FooBarsAssociationExtension (NameError)
which can be easily reproduced running the following code:
{syntaxhighlighter brush:ruby}
require 'rubygems'
require 'activerecord'
module FooBar
class Foo < ActiveRecord::Base
has_many (:bars) do
def by_name(name)
find(:all, :conditions => ["name = ?", name])
end
end
end
class Bar < ActiveRecord::Base
end
end
{/syntaxhighlighter }
This can be fixed by removing the module FooBar declaration, but can one imagine living without modules?
Knowing the Ruby community, I bet that this bug will stay unfixed for a while. Time for AnUgLyPaTcHpArTy!