何时扩展ActiveRecord :: ConnectionAdapters :: TableDefinition?

时间:2011-01-07 21:13:41

标签: ruby-on-rails ruby ruby-on-rails-3

我想在ActiveRecord :: ConnectionAdapters :: TableDefinition中添加一个或两个方法;我什么时候加载我的代码?我尝试在Application.initialize之后立即通过require加载它!在config / environment.rb中,但随后出现了错误 -

uninitialized constant ActiveRecord::ConnectionAdapters::TableDefinition (NameError)

顺便说一句,我在Rails 3.0.3上。我试图加载的代码看起来像这样 -

class << ActiveRecord::ConnectionAdapters::TableDefinition
  def my_extension(*args)
    options = args.extract_options!
    ... some stuff is done here ...
  end
end

1 个答案:

答案 0 :(得分:0)

尝试将源文件放在config/initializers中。找到的任何.rb文件都应该由Rails自动加载。